How to make a component invisible, without changing the location of other elements

我怕爱的太早我们不能终老 提交于 2019-12-10 18:40:20

问题


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.


回答1:


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.




回答2:


I use the setVisible (false)

Try instead setEnabled(false). It won't remove the visual representation of the button, which fixes the layout, but will make it not focusable and look different. This is the 'path of least surprise' for the typical end user.


Location manager is GridBagLayout.

BTW - if you are stuck on making the button invisible, a GridLayout would achieve the effect of retaining the positions of the other buttons.




回答3:


There are two buttons: "Next" & "Back", this is reason for using CardLayout



来源:https://stackoverflow.com/questions/9495463/how-to-make-a-component-invisible-without-changing-the-location-of-other-elemen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!