简体   繁体   English

Java Applet中的setVisible无法正常工作

[英]setVisible in Java Applet not working

I am writing a Java applet, in my applet I simply call setVisible() to control the visibility of some panels. 我正在编写一个Java applet,在我的applet中,我只是调用setVisible()来控制某些面板的可见性。

For example: 例如:

pnlAddUser.setVisible(true);

but sometimes showing panel does not work. 但有时无法显示面板。 and when I just click on the border of Applet Viewer window, the panel appears. 当我只单击Applet Viewer窗口的边框时,将出现该面板。

I used: 我用了:

  • invalidate() invalidate()
  • setSize(this.getWidth(), this.getHeight()) setSize(this.getWidth(),this.getHeight())
  • this.repaint(this.getGraphics()); this.repaint(this.getGraphics());
  • pnlAddUser.repaint(); pnlAddUser.repaint();

but it doesn't work. 但这不起作用。

Edit: I should mention, I am using a JTree and when a TreeNode is selected, I show or hide some panels according to the type of the node. 编辑:我应该提到,我正在使用JTree,并且当选择TreeNode时,我会根据节点的类型显示或隐藏一些面板。

Please help me, Thanks. 请帮助我,谢谢。

Solved. 解决了。 Not good but it works. 不好,但是有效。

I added the code: 我添加了代码:

public void repaintAgain() {
    setSize(this.getWidth() - 1, this.getHeight() - 1);
    setSize(this.getWidth() + 1, this.getHeight() + 1);
}

whenever I want to repaint, use this. 每当我想重新粉刷时,都可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM