• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

GridBagLayout Problem

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 121
12
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without code to look at , I think you are not setting your textfield size

-Agad
 
Replace the word "snake" with "danger noodle" in all tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic