Dima Maligin
Dima Maligin

Reputation: 1482

GridBagConstraints filling both VERTICAL & HORIZONTAL

How do I go about filling both the vertical and horizontal space available in the grid cell of interest?

For example:

JTextArea file1 = new JTextArea();
file1.setBorder(BorderFactory.createLineBorder(Color.black));
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0 / ELEMENTS_IN_WIDTH;
c.weighty = 0.9;
c.insets = new Insets(PAD, PAD, PAD, PAD);
c.fill = GridBagConstraints.VERTICAL;
mainPanel.add(file1, c);

This fills the cell vertically but not horizontally.

Obviously adding c.fill = GridBagConstraints.HORIZONTAL after the VERTICAL value will only override the value of c.fill

OR'ing them like c.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL also doesn't do the trick.

Upvotes: 1

Views: 2969

Answers (2)

mostar
mostar

Reputation: 4821

You should use:

GridBagConstraints gridConst = new GridBagConstraints();
gridConst.fill = GridBagConstraints.BOTH;

Upvotes: 6

Dima Maligin
Dima Maligin

Reputation: 1482

I was to hasty and missed the obvious field of GridBagConstraints.BOTH. The issue is now resolved... sorry for the false bother.

Upvotes: 2

Related Questions