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().

This should do the trick.

It seems that there is no such thing as an editable JList considering that a JList component is for display purposes only. A workaround that programmers often do is to use a 1 column JTable instead.

If you really want to use an editable JList, a coder named Santosh Kumar made his very own class to do just that. Google his name plus the keyword “editable JList“.

For simplicity’s sake though, use a JTable since the component is already there. And there is nothing hard using a JTable if you already used one before. Just hide the headers and you will be all set.

Still, I cannot help but think why Sun did not provide an option to make a JList component editable.

Related Posts Plugin for WordPress, Blogger...