Color Not Applied In JTextPane If Disabled
Posted by blogmeister on
July 29, 2012
So I had a JTextPane that displays text in HTML format. The color issue arises when I disable the JTextPane. A workaround to this is to use the setEditable() method instead of setEnabled().
Then again, another issue arises. You will be able to select the text even though you cannot insert or remove characters in the JTextPane. If you do not want the JTextPane to have a selection feature if it is not editable, then only way to make it work is to override its protected method processMouseEvent().
|
1 2 3 4 5 6 7 |
JTextPane txtpane = new JTextPane() { @Override protected void processMouseEvent(MouseEvent me) { if (isEditable()) super.processMouseEvent(me); } }; |
This should do the trick.









