Laird Nelson is happiest immersed in server-side frameworks and middleware, where he has spent the better part of nine years obsessed with software reuse.? He has worked for both the Davids and Goliaths of the Boston area as engineer, architect, reuse evangelist, contractor and consultant.? He also plays a mean Hammond B3.
This one tripped me up, and I thought I'd post it here. I have a case where I need to pour text into a JTextField, but have that JTextField look like a JLabel. So as I type in one field, I need this "gray" second field to update, live, before the user's eyes. I also need the ability for the user to cut-and-paste values out of it. This sort of thing is reasonably common in properties panels and the like.
Now, normally all you have to do is something like this:
final JTextComponent previewComponent = new JTextField();
previewComponent.setBorder(null);
previewComponent.setEditable(false);
previewComponent.setOpaque(false);
...and you have what looks like a JLabel but what behaves like a JTextField.
Well, except under Nimbus, where the setOpaque(false) seems to have no effect. Turns out you need to also set the background color to a transparent color as well. Fortunately, this combination of behaviors seems to work under all the other look and feels (looks and feels?):