I haven't used Swing too much, but I've recently run into a problem
that I'm not sure how to fix. When I remove all components from a
JPanel and then add new components to it, the panel displays the new
components if they are AWT components, but not if they're Swing
components. Example
import java.awt.*;
import javax.swing.*;
public class test extends JFrame
{
public static void main(String[] args)
{
new test();
}
public test()
{
JPanel panel = new JPanel();
panel.add(new Button("a"));
panel.add(new Button("b"));
getContentPane( ).add(panel);
pack();
show();
try{Thread.slee p(3000);}catch( Exception ex){}
panel.removeAll ();
panel.add(new Button("c"));
panel.add(new Button("d"));
panel.repaint() ;
}
}
This works fine. But if I change Button to JButton everywhere, then
the panel goes blank after 3 seconds. Can anyone tell me why this
happens?
Thanks in advance
that I'm not sure how to fix. When I remove all components from a
JPanel and then add new components to it, the panel displays the new
components if they are AWT components, but not if they're Swing
components. Example
import java.awt.*;
import javax.swing.*;
public class test extends JFrame
{
public static void main(String[] args)
{
new test();
}
public test()
{
JPanel panel = new JPanel();
panel.add(new Button("a"));
panel.add(new Button("b"));
getContentPane( ).add(panel);
pack();
show();
try{Thread.slee p(3000);}catch( Exception ex){}
panel.removeAll ();
panel.add(new Button("c"));
panel.add(new Button("d"));
panel.repaint() ;
}
}
This works fine. But if I change Button to JButton everywhere, then
the panel goes blank after 3 seconds. Can anyone tell me why this
happens?
Thanks in advance
Comment