I need a JTextField with a JLabel style (in other words, I need a JLabel but I want to be able to select the text).
JTextField value = new JTextField(valueText);
value.setEditable(false);
value.setBorder(BorderFactory.createEmptyBorder);
value.setForeground(UIManager.getColor("Label.foreground"));
value.setFont(UIManager.getFont("Label.font"));
value.setBackground(UIManager.getBackground("Label.background"));
...
It works fine on Windows and Mac:
but on Ubuntu (GTKLookAndFeel) I get the next result:
Where "By" is the JTextField and "Size" is a JLabel
Finally I got the expected result using JEditorPane instead of JTextField:
JEditorPane value = new JEditorPane();
value.setText(valueText);
...
It seems that GTK Look and Feel does not allow a custom background in the JTextField: https://bugs.java.com/bugdatabase/view_bug?bug_id=6531760