I have created a JPanel and set its layout to BoxLayout with components laid out from top to bottom. I then add buttons to the panel but the buttons are centred within the column-shaped panel. How do I get them to "float" to the top ?
you can add them to another JPanel which has a flowlayout manager, and then add that panel to your box layout.
A box layout only gives you a choice of either X ior Y alignment, both mutually exclusive. If you want a screen with buttons at the top, try using a borderlayout and then add a panel containing the 3 buttons to the NORTH part of the borderlayout.
Box layout is complex to use and is normally only suitable for when there are frame resizing issues you need to address (i.e. it allows you to apply glue to certain compennets whilst letting other float around as the frame is resized etc).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.