Campbell Ritchie wrote:You should use the Layout manager which corresponds to your component. What are you adding those buttons to? Is it a panel? Remember that panels default to flow layout, so your buttons will congregate near the top. Remember the layout manager can override any other location and size information.
1: Go through the Java™ Tutorials section about layouts: here it is. 2: Don't set the content pane on your frame. Leave its default value. Call add() rather than getContentPane().add() 3: Call the set preferred size method on both buttons. Make sure to give them reasonable values. 4: Add a panel to the frame with border layout.SOUTH or PAGE_END. Remember a j frame defaults to border layout. 5: Add your buttons to that panel, which defaults to flow layout and (I think) the components distribute around its midline. You may have to call pack() on the panel. Not sure about that last point.You may have to do similar things with the check boxes to get them where you want them.
Campbell Ritchie wrote:You're welcome
In future make sure to tell people on both fora if you post in two locations.
Campbell Ritchie wrote:
•3: Call the set preferred size method on both buttons. Make sure to give them reasonable values.
•5: You may have to call pack() on the panel. Not sure about that last point.
Fred Kleinschmidt wrote:Why set the preferred size of a button? You should let the buttons determine their own preferred size.
Campbell Ritchie wrote:2: Don't set the content pane on your frame. Leave its default value. Call add() rather than getContentPane().add()
Brian Cole wrote: it's ok to set the preferredSize of a component, but it's not ok to set the bounds (or the size, which is part of the bounds) of a component. It's the layout manager's job to set the bounds, not yours.
Rob Camick wrote:You should not be using the setPreferredSize() method since it is the responsibility of each component to determine its own size so the layout manager can do its job.
If you do use the setPreferredSize() then you are in effect setting the "size" of the component since many layout manager respect the preferred size of the component. So this will diminish the effectiveness of the layout manager.
It is simply quicker to add things directly to a JFrame than to change its content pane.That sort of code allows you to use several panels with different layouts.
Brian Cole wrote:. . . is add() stuff directly to the panel before setting the panel as the content pane. It's just a personal preference. . . .