wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout Problem" Watch "GridBagLayout Problem" New topic
Author

GridBagLayout Problem

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
I have set a GridBagLayout so that it span only one column, when it is fully expanded due to fill = GridBagConstraints.HORIZONTAL;, I can see it extend about 1/3th size of the
form, however, when it is none, it shrinks to about a couple of pixels of the width. I set the JTextField by
JTextField tf = new JTextField(50);
how can I set the width of the component according to my will?
Thanks
Jack

Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 103
    
  11
Did you set to GridBagConstraints.weightx to a non-zero value? It's a common mistake to not set weightx/weighty to any cell in a grid. HORIZONTAL describes how a component will fill cell. And weight defines in which ratio cells will grow when there are more available space for GridBag.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Maxim Karvonen wrote:Did you set to GridBagConstraints.weightx to a non-zero value? It's a common mistake to not set weightx/weighty to any cell in a grid. HORIZONTAL describes how a component will fill cell. And weight defines in which ratio cells will grow when there are more available space for GridBag.


Hi Maxim,
I've set the weightx to 0.5 for every same row, but if I set one of them to 1, the other rows extend along and having the same width as the largest one.
Thanks
Jack
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

It is not easy to understand the problem unless we see a SSCCE and maybe a picture of what it is and what you expect.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Agador Paloi
Ranch Hand

Joined: Jan 24, 2006
Posts: 118
Without code to look at , I think you are not setting your textfield size

-Agad
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: GridBagLayout Problem