The moose likes Swing / AWT / SWT and the fly likes setPreferredSize() vs GridBagConstraints.fill ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setPreferredSize() vs GridBagConstraints.fill ?" Watch "setPreferredSize() vs GridBagConstraints.fill ?" New topic

setPreferredSize() vs GridBagConstraints.fill ?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
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 :-)

humanum errare est.
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
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

Joined: Jul 03, 2001
Posts: 2120
I have only found setPrerredWidth on TableColumn. Do you mean that one?

SCJP2. Please Indent your code using UBB Code
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
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:
subject: setPreferredSize() vs GridBagConstraints.fill ?
Similar Threads
how to make my jtextfield smaller ?
Problem of JComboBox:
JTable in JScrollPane
restrictions on resizing JFrame