Home / Java Patterns and Pitfalls     frequal.com

Rectangular Disabled Nimbus JTextField

In the Nimbus Swing Look and Feel (LAF), JTextFields appear just like JLabel's in their normal disabled state. Sometimes you want them to look like normal rectangles.

To do so, copy the settings from the enabled state to the disabled state. Be sure to do this in the Event Dispatch Thread (EDT) prior to showing your first window:

UIManager.getLookAndFeelDefaults().put("TextField[Disabled].backgroundPainter", UIManager.getLookAndFeelDefaults().get("TextField[Enabled].backgroundPainter")); UIManager.getLookAndFeelDefaults().put("TextField[Disabled].borderPainter", UIManager.getLookAndFeelDefaults().get("TextField[Enabled].borderPainter")); If you are using FormattedTextFields, repeat the above modifying the strings to say FormattedTextField.

Last modified on 24 Feb 2013 by AO

Copyright © 2016 Andrew Oliver