java窗体切换代码,从一个jframe切换到另一个jframe时,Java中的Swing GUI问题。

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();

解决方案I assume you''re trying to create the components newly. that results in a overloaded GUI with to much components to be shown. so some of them are rendered in positions that you cannot see - behind other components or outside the frame area.

How about just changing a the JPanel in a constant JFrame? You could dispose the non valid JPanel and create a new fresh one.

Also do you have a facade for the data?? You should have one, it''s much easier to create the components with the new values from scratch.

Just removed all the components from the Jpanel.

Not the best of solutions but it works.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值