本文介绍了从一个jframe切换到另一个jframe时,Java中的Swing GUI问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序有两个窗口.我们称它们为窗口A和窗口B.

当用户加载程序时,将显示窗口A,该窗口允许用户加载.txt文件.该.txt文件包含
窗口B正常工作的重要数据.加载.txt文件时,用户单击一个按钮,然后窗口B加载,并使用来自窗口A的.txt文件中的数据正确显示.

没问题.

当我想使用其他.txt文件时,就会出现问题.在窗口B上,我有一个按钮可以再次加载窗口A,以使用户键入不同的值.当用户单击按钮以再次加载窗口B时,我的所有挥杆组件均无法正确显示.在窗口B中,我使用BorderLayout,所以当我用新值重新加载窗口B时,BorderLayout的右侧似乎消失了.我认为我的程序正在做的是彼此重装所有组件,这就是为什么它提供奇怪结果的原因,我只是想知道如何解决此问题.

问题不在于.txt文件中的新值,因为.txt文件中的值不会与swing组件交互.

这是我从窗口B加载窗口A时要让用户键入不同值的代码.

My program has two windows. Lets call them Window A and Window B.

When the user loads up the program Window A appears which lets the user load up a .txt file. This .txt file contains
important data for Window B to work correctly. When the .txt file is loaded, the user clicks on a button and Window B loads up and using the data from the .txt file from Window A to correctly display.

No problem.

The problem comes when I want to use a different .txt file. On Window B I have a button which loads up Window A again to let the user type in different values. When the user clicks on the button to load Window B up again all my swing components don''t display correctly. In Window B I use a BorderLayout, so when I reload Window B with the new values the right hand side of the BorderLayout seems to disappear. I think that what my program is doing is reloading all the component on-top of each other which is why it providing strange results and I am just wondering how I can rectify this issue.

The problem doesn''t lie with the new values from the .txt files, as the values from .txt file doesn''t interact with the swing components.

Here is the code I have when loading Window A from Window B to let the user type in different values.

WindowA.startFrame.setVisible(true);
WindowB.guiFrame.invalidate();
WindowB.guiFrame.dispose();

推荐答案



这篇关于从一个jframe切换到另一个jframe时,Java中的Swing GUI问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:08