JackIngleton
JackIngleton

Reputation: 147

GridBagLayout set JScrollPane relative to JButton height

I've created a GridBagLayout with a JScrollPane(JTextArea) in the first row (spanning 3 columns) and 15 JButtons in the other 5 rows (each button spans 1 column).

I have set the weights so that all of the components expand equally as the window is resized, and the frame minimum size to its preferred size. However, I'd like the height of the JScrollPane to be 5 * the height of each JButton (half of the total frame height). Is there a simple way to enforce this?

Upvotes: 1

Views: 104

Answers (1)

camickr
camickr

Reputation: 324098

However, I'd like the height of the JScrollPane to be 5 * the height of each JButton (half of the total frame height). Is there a simple way to enforce this?

If you want the area to be half the height then use a different layout manager.

Create a JPanel that uses a GridLayout. This way each component will be the same size.

Then add the scrollpane to the panel. Then create a second panel that also uses a GridLayout. Add the buttons to this panel and then add this panel to the main panel.

The bottom line is you can use multiple panels each with different layout managers to achieve your desired result.

Upvotes: 3

Related Questions