Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setPreferredSize() vs GridBagConstraints.fill ?

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
In my applets, I found that for my components e.g. JTextField, GridBagConstraints.fill = GridBagConstraints.HORIZONTAL would take precedence over component.setPreferredSize(new Dimension(75,17)). In practice, this renders setPreferredSize spurious in a GridBagLayout.
Is this your understanding on how it works, that one either uses fill or setPreferredSize ?
TIA :-)
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I've answered my own question on this one.
Better stick with GridBagLayout paramaters, its much simpler that way.
On the other hand, if I use them with setPreferredWidth, I achieve some amazing results in terms of granularity. The flip side is its complexity. It seems to interact with GridBagLayout's allocation of column width.
Has anyone tried something like that?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have only found setPrerredWidth on TableColumn. Do you mean that one?
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am using jKomponent.setPreferredWidth(new Dimension(int x, int y)) on JTextFields in a GridBagLayout using only GridBag components such as gridx and gridy.
I am happy with it to the extent that it also allows me to fit 2 components into one "cell" , bound by the same gridx and gridy, like this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic