?
Solved

GridBagLayout hates JComboBox

Posted on 2003-03-14
7
Medium Priority
?
458 Views
Last Modified: 2012-05-04
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
Comment
Question by:shew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8141457
No it handles all components the same.
Any difference would be probably be because of different min/max/preferred dimension sizes.
0
 

Author Comment

by:shew
ID: 8141489
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
 
LVL 92

Expert Comment

by:objects
ID: 8141511
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
Industry Leaders: 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!

 

Author Comment

by:shew
ID: 8141519
Are you suggesting that JComboBox has different internal size constraints that JTextField does not?  Size constraints that I do not control?
0
 
LVL 92

Accepted Solution

by:
objects earned 375 total points
ID: 8144632
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
 

Expert Comment

by:CleanupPing
ID: 9058680
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
 
LVL 92

Expert Comment

by:objects
ID: 9066444
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question