Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top