Link to home
Start Free TrialLog in
Avatar of shew
shew

asked on

GridBagLayout hates JComboBox

I have a basic JPanel with a layout manager of GridBagLayout.  I am trying to add Labels and Fields to the panel in a basic label field, label field paradigm.

------------------------------------------------
-  Label:  JTextField Label:  JTextField       -
-  Label:  JTextField Label:  JTextField       -
-  ...                                         -
------------------------------------------------

The problem that I am running into is with the differences in JComboBox and JTextField when it comes to setting weights on this basic JPanel.  I have set each label to have a weightx of 0 and each FieldBox (they are randomly either JTextField or JComboBox components) to weightx of 1.  The problem I am seeing is that if I have all JTextFields except for one JComboBox in one column, that column gets twice as much size as the other column.

----------------------------------------------------------------
-  Label:  JTextField Label:  JComboBoxxxxxxxxxxxxxxxx         -
-  Label:  JTextField Label:  JTextFieldxxxxxxxxxxxxxx         -
-  ...                                                         -
----------------------------------------------------------------

Does anyone know if GridBagLayout handles these two components differently?

Thanks!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

No it handles all components the same.
Any difference would be probably be because of different min/max/preferred dimension sizes.
Avatar of shew
shew

ASKER

The field components do not have size constraints (no setSize or setPreferredSize being called).  One thing I forgot to mention was they they are both actually JPanels that contain either a JComboBox or a JTextField.  Not sure if that would have anything to do with it.  

It appears as thought GridBagLayout is allowing the JComboBox to be exactly twice the size of the JTextField.

:(
Just because you have not set any size constraints doesn't mean they don't have any, all components do.
Repeating, it does not treat the componentents differently.
Avatar of shew

ASKER

Are you suggesting that JComboBox has different internal size constraints that JTextField does not?  Size constraints that I do not control?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
shew:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.