|
I believe I have found a bug when setting the enabled state
to false for a ULCTextField and ULCPasswordField using the Windows look and
feel. I have included screen shots as well as test cases. For the
test cases, I have provided equivalent ULC and Swing implementations to see
whether this was a Swing bug or ULC bug. Perhaps there is something special I need to do in the ULC
case, but I wasn’t able to find the setting to get around this issue. Here are the details:
See screen shots:
This is an important look and feel issue since the initial
state shown in ULC implies that the field is enabled, when in fact it isn’t.
Please note that is only happens when running on Windows and setting the
look and feel using UIManager.getSystemLookAndFeelClassName(). If the
default Metal Look and Feel is used, the disabled background color is initially
correctly set. Kind regards, Les |
<<attachment: swing_disable_initial_step.jpg>>
<<attachment: ulc_disable_initial_step.jpg>>
<<attachment: ulc_disable_after_state_change.jpg>>
import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.util.List;
import javax.swing.*;
public class SwingDisableTest {
public void start() {
JFrame frame = new JFrame("Swing Disable Test");
frame.getContentPane().setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(createTestPanel(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
private JPanel createTestPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.insets = new Insets(3,3,3,3);
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
final JCheckBox checkBox = new JCheckBox("Test Disabled State");
final JComboBox comboBox = new JComboBox(createTestComboBoxModel());
comboBox.setEnabled(false);
final JTextField textField = new JTextField(20);
textField.setText("test");
textField.setEnabled(false);
final JPasswordField passwordField = new JPasswordField(20);
passwordField.setEnabled(false);
checkBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
comboBox.setEnabled(checkBox.isSelected());
textField.setEnabled(checkBox.isSelected());
passwordField.setEnabled(checkBox.isSelected());
}
});
panel.add(checkBox, gbc);
panel.add(comboBox, gbc);
panel.add(textField, gbc);
panel.add(passwordField, gbc);
return panel;
}
private DefaultComboBoxModel createTestComboBoxModel() {
List<String> testList = new ArrayList<String>();
testList.add("one");
testList.add("two");
testList.add("three");
return new DefaultComboBoxModel(testList.toArray());
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SwingDisableTest test = new SwingDisableTest();
test.start();
}
}
import java.util.ArrayList;
import java.util.List;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.BorderFactory;
import com.ulcjava.base.application.DefaultComboBoxModel;
import com.ulcjava.base.application.IComboBoxModel;
import com.ulcjava.base.application.ULCBorderLayoutPane;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCCheckBox;
import com.ulcjava.base.application.ULCComboBox;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCPasswordField;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.development.DevelopmentRunner;
public class ULCDisableTest extends AbstractApplication {
public void start() {
ULCFrame frame = new ULCFrame("ULC Disable Test");
ULCBorderLayoutPane pane = new ULCBorderLayoutPane();
frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
pane.add(createTestPane(), ULCBorderLayoutPane.CENTER);
frame.add(pane);
frame.pack();
frame.setVisible(true);
}
private ULCBoxPane createTestPane() {
ULCBoxPane pane = new ULCBoxPane();
pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
ULCCheckBox checkBox = new ULCCheckBox("Test Disabled State");
ULCComboBox combo = new ULCComboBox(createTestComboBoxModel());
combo.setEnabler(checkBox);
combo.setEnabled(false);
ULCTextField name = new ULCTextField(20);
name.setText("test");
name.setEnabler(checkBox);
name.setEnabled(false);
ULCPasswordField pass = new ULCPasswordField(20);
pass.setEnabler(checkBox);
pass.setEnabled(false);
pane.add(ULCBoxPane.BOX_LEFT_CENTER, checkBox);
pane.add(ULCBoxPane.BOX_LEFT_CENTER, combo);
pane.add(ULCBoxPane.BOX_LEFT_CENTER, name);
pane.add(ULCBoxPane.BOX_LEFT_CENTER, pass);
return pane;
}
private DefaultComboBoxModel createTestComboBoxModel() {
List<String> testList = new ArrayList<String>();
testList.add("one");
testList.add("two");
testList.add("three");
return new DefaultComboBoxModel(testList.toArray());
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DevelopmentRunner.setApplicationClass(ULCDisableTest.class);
DevelopmentRunner.run();
}
}
