File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout Problem

 
Jacky Luk
Ranch Hand
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
12
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Agador Paloi
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without code to look at , I think you are not setting your textfield size

-Agad
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic