• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

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!
0
shew
Asked:
shew
  • 4
  • 2
1 Solution
 
objectsCommented:
No it handles all components the same.
Any difference would be probably be because of different min/max/preferred dimension sizes.
0
 
shewAuthor Commented:
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.

:(
0
 
objectsCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shewAuthor Commented:
Are you suggesting that JComboBox has different internal size constraints that JTextField does not?  Size constraints that I do not control?
0
 
objectsCommented:
All components have different default size constraints, it wouldn't make sense if all components were the same size. You are free to change these constraints to meet these requirements.
0
 
CleanupPingCommented:
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.
0
 
objectsCommented:
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now