如何在不更改其他元素位置的情况下使组件不可见 [英] How to make a component invisible, without changing the location of other elements

查看:91
本文介绍了如何在不更改其他元素位置的情况下使组件不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个按钮:下一步"和"返回"以传递列表.到达终点时,下一步"按钮消失,但后退"按钮不应跳到她的位置.我使用setVisible (false),但是按钮返回"跳到下一步"的位置.位置管理器是GridBagLayout.

There are two buttons: "Next" & "Back" to pass on the list. When the reached the end, the button "Next" to disappear, but the button "back" should not jump to her place. I use the setVisible (false), but the button 'Back' jump to the place of the "Next". Location manager is GridBagLayout.

推荐答案

将按钮与一个或多个空JPanel(或JLabel)一起放置在具有CardLayout的容器JPanel中.当您想隐藏按钮时,只需在容器中交换卡即可.

Place the button in a container JPanel with CardLayout together with one more empty JPanel (or JLabel). When you would like to hide the button just swap cards in the container.

这篇关于如何在不更改其他元素位置的情况下使组件不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆