简体   繁体   English

使用JLayeredPane方法repaint()吗?

[英]Use method repaint() with JLayeredPane?

I write simple application and I have problem with repaint().I have one JLayeredPane where I putted components. 我写了一个简单的应用程序,但repaint()遇到了问题。我在其中放置了一个JLayeredPane。 I want to make button reset,and when he is clicked to set JLayeredPane to default look. 我想重置按钮,并单击他以将JLayeredPane设置为默认外观。

layeredPane.removeAll();
ayeredPane.revalidate();
layeredPane.repaint();

But when button is clicked the JLayeredPane didn't reset to default.` 但是,当单击按钮时,JLayeredPane并未重置为默认值。

Can somebody help me how I can do it? 有人可以帮我怎么做吗?

Read the section from the Swing tutorial on How to Use Layered Panes . 阅读Swing教程中有关如何使用分层窗格的部分 Download the demo code. 下载演示代码。 It will show you how to properly structure a program. 它将向您展示如何正确构造程序。

Make the following change to the code: 对代码进行以下更改:

if (ON_TOP_COMMAND.equals(cmd)) {
    layeredPane.removeAll();
    layeredPane.repaint();
  1. Run the program to prove it displays the layered panes. 运行程序以证明它显示了分层窗格。

  2. Click on the "Top Position in Layer" checkbox and the layers will disappear. 单击“图层中的最高位置”复选框,图层将消失。

So you have proven the code should work. 因此,您已经证明代码可以正常工作。 If it doesn't work for you then maybe you don't have a valid reference to the layered pane. 如果它对您不起作用,则可能您没有对分层窗格的有效引用。

If you need more help then post a proper SSCCE that demonstrates the problem because we can't help based on the code provided since it should work, to the problem is somewhere else in your program. 如果您需要更多帮助,请发布适当的SSCCE来说明问题,因为我们无法根据提供的代码来帮忙,因为它应该可以解决问题,这是您程序中的其他问题。

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

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