Mnemonics are those underlined letters that you see in labels and buttons that when activated via the ALT key + the letter, will activate that label/button.

However, when a JTable is included in the user interface and has editing capabilities enabled, you may be surprised that instead of activing a button by pressing ALT + key on the keyboard, the JTable activates editing mode.

How to fix it then? You need to override the processKeyBinding() method of the JTable class. Do it like this

This solution was from a forum called Java.net and fixed this mnemonic problem when a JTable with cell editors is present in the same user interface area.

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.

Sure. Setting a JTable column header’s background color is very easy. Just call

But once you run it, there may be times you will not see any changes. I am not sure if this happens all the time but this surely did happen to me and it took me a very, very long time to figure out how to make this work.

All it took was one method call.

Do that, and your background color should now appear.

Related Posts Plugin for WordPress, Blogger...