-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.2.0
-
x86
-
windows_nt
Name: el35337 Date: 05/18/98
Using Swing 1.0.2:
Reference bug: 4095736
JTextField (really JTextComponent) does not cause repaint when the enabled state changes.
The code behind JTextComponent.setEnabled does call the repaint() method, but...
Simply calling a repaint() after the enabled state changes is not working. I beleive it is not working because no dirty region has been indicated on the component, and the RepaintManager ignores the repaint request because it doesn't think there is anything on that component that needs to be redrawn.
Poking around, I found out how JLabel manages doing this correctly: instead of calling repaint(), the JTextComponent should call repaint(10), which will force the entire component to be repainted. (Rather than just suggesting that it should be repainted...)
// Example of bug id: 30055
// By John Zollinger, Arkona, Inc.
// ###@###.###
import java.awt.*;
import com.sun.java.swing.*;
import java.awt.event.*;
public class MyFrame extends JFrame {
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
public MyFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
this.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}}
);
}
public static void main(String[] args) {
try {
//UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
//UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());
}
catch (Exception e) {
}
MyFrame frame1 = new MyFrame();
frame1.setSize(new Dimension(400, 100));
frame1.setVisible( true );
}
private void jbInit() throws Exception {
jTextField1.setText("This text should look disabled after the button is clicked.");
jButton1.setText("Click to disable text field");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
this.getContentPane().add(jTextField1, BorderLayout.NORTH);
this.getContentPane().add(jButton1, BorderLayout.CENTER);
}
void jButton1_actionPerformed(ActionEvent e) {
jTextField1.setEnabled( false );
jButton1.setText("TextField disabled, does it look it? Try selecting the text and see what happens.");
// Uncomment the following line to force the text field to repaint itself
// which will cause it to display itself properly after it's enabled state
// is changed.
//jTextField1.repaint( 0 );
}
}
(Review ID: 30055)
======================================================================