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!
--------------------------
- 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!
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.
:(
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.
Repeating, it does not treat the componentents differently.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
Any difference would be probably be because of different min/max/preferred dimension sizes.