开发者

Swing: setContentPane not refreshing the interface when called

开发者 https://www.devze.com 2023-01-30 01:37 出处:网络
I\'m having a problem with my applet: it doesn\'t refresh when I need it to. I\'m trying to switch from one interface screen to the other when I click on the button.

I'm having a problem with my applet: it doesn't refresh when I need it to.

I'm trying to switch from one interface screen to the other when I click on the button.

I have a

public class PixelRainEditorApp extends JApplet

and in the init

SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
        createGUI();
    }
});
private void createGUI() {
    a = new A(this);
    this.setSize(800, 480);
}

Then I have 2 classes A and B that extend JPanel

public A(JApplet parent) {
   super(parent);
   setOpaque(true);
   setBackground(Color.BLACK);
   this.parent.setContentPane(this);
}

when I click on a button in view A

@Override
public void actionPerformed(ActionEvent e) {
   if(TAG.equalsIgnoreCase(e.getActionCommand())){
      new B(this.baseParent);
   }
}

and B is the same as A but with different images

public B(JApplet parent) {
       super(parent);
       setOpaque(true);
       setBackground(Color.BLACK);
       this.parent.setContentPane(this)开发者_开发技巧;
    }

Now this works fine when I want to display A, but when I want to launch B when I click on a button in A, nothing happens. Its only when I resize the window that B appears... I tried to invalidate or repaint and various places in my applications but nothing happens

Any ideas ?

Jason


Just add this.parent.revalidate(); this.parent.repaint(); in th end of your calls.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号