Maximum size of a JComboBox in a GridBagLayout
I'm having a problem with a JComboBox inside a GridBagLayout. The general layout is a GridBag with labels / combo / textfields on the first line, a large table in a scrollpane that takes all columns on the second line, and a few labels / combo / textfields on the third.
As long as the combo on the first combo is empty, it looks fine. When it gets populated, the combo gets resized to the size of the largest text. I would like to have it smaller and truncate the text.
I tried to set maximum size, but the GridBag doesnt care. I've been trying with weightx but no success.
What should I do ?
[620 byte] By [
gehel] at [2007-11-26 12:16:45]

# 2
I tried that as well, and the setSize, but none seem to work. Is there a good introduction on the GridBagLayout and maybe ComboBox somewhere ? I cant find any that really goes into the details of how it works. Or at least, I havnt understood yet ...Thanks for the hint anyway !
gehel at 2007-7-7 14:53:17 >

# 3
> I cant find any that really goes into the details of how it works.
[url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers[/url]. I don't like using GridBagLayout because of all the constraints available. Its flexible but confusing. I think you might need to use the weightX constraint.
# 4
Hello camickr!
I like reading your posts here. You are always precise and .... I dont know the correct word! You often get answers like "do not get rude" or something like that but I think that you are honest and you say squarely what you are thinking. I like that!
And I would be interested which LayoutManager you prefer using. Because for me the GridBagLayout is often some kind of trial and error game, which I do not like! I noticed that there is a new layout, the SpringLayout. For you it might be rather old but I just try to get into Java again after being involved most of my time in the project "Raising two kids". What about it? When I read the tutorial it seemed confusing and complicated to me, too.
Thanks!
Annette
# 5
> And I would be interested which LayoutManager you prefer using.
I don't use a single Layout Manager. I use a combination of Layout Managers to do the job. Thats why this question doesn't have a specific example. Remember LayoutManagers can be nested. The default layout manager for a frame is a border layout. That great for the general look of your application.
a) you add a toolbar to the north
b) you add a status bar to the south
c) you add your main panel to the center.
the main panel in turrn may use nested panels depending on your requirements. I don't do a lot of screen design but I typically use BorderLayout, FlowLayout, GridLayout and BoxLayout. GridBagLayout and SpringLayout have too many constraints to learn and master. They may be good for a GUI tool that only uses a single layout manager for the entire GUI, but I believe a better design is to break down the form into smaller more manageable areas and group components and use the appropriate layout manager for the group. That may or may not be a GridBagLayout for the small group, but I don't think you should force the entire form to use a GridbagLayout.
# 6
Yep, I like your answer a lot !The code I'm working with was generated by a graphical tool, and looks a bit too much like generated code. It makes it quite hard to change it. But I think I will need to take the time to get into that approach.Thanks for your advices !
gehel at 2007-7-7 14:53:17 >
