2

When I start my program I create the MainFrame. When I click on the button "search", I show another JFrame. If it obtains results on the search, the goal is to fill the information in MainFrame.

It's all working. But to be able to display the information, I have to re-create the MainFrame. What means, that the two MainFrame's stay open.

How do I hide the first?


Supose thet i have only the MainFrame and one dialog with the Search form.

When i click on ok button on the search dialog, i have some info.

In the MainFrame Class i know that the info is there.

I have the settext on the textfield's, etc... and on the final line i have the "setvisible(true)".

But they remain blanc! Why??


Can anyone post here an example, how to do it? Please

I just search for all options, but i can't solve.

4

3 回答 3

7

JFrameSwing 应用程序最多应包含一个。如果您需要显示多个“窗口”,那么您可以使用多个JDialog和使用dispose()来隐藏对话框。

或者,您可以使用 aCardLayout作为布局管理器,而不是使用太多对话框。

看:

于 2012-12-26T19:46:01.897 回答
0

用于JFrame.setVisible(false)隐藏,并JFrame.setVisible(true)使其重新出现。这将适用于 swing 中的任何 JComponent,而不仅仅是 JFrame。

于 2012-12-26T19:45:19.700 回答
0

您可以通过调用该方法来隐藏 JFrame:

   setVisible(false);

但是,您可以考虑改用 JDialogs,因为您可以选择创建模式对话框,这意味着用户只能在搜索对话框打开时与它进行交互。

于 2012-12-26T19:45:48.260 回答