Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Changing size of JComboBox

 
harshi Sum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new to java Applets.I'm trying to implement an expert system with the help of jess and java Applets.
My applet have 2 "JComboBox" objects. I have used the grid layout as a layout manager.


I want to set size of the "combobox" , because it appears too large and very ugly. (Actually i want to arrange the things in a proper manner that it would look nice).
I have tried with "setMinimumSize" and "setSize". But it seems the grid layout is ignoring them.

Here is my code.


Can someone please help me........ Thanks in advance.

Vidu.


this is the query.clp file (just in case needed)
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags next time. I've added them for you this time.

harshi Sum wrote:I want to set size of the "combobox" , because it appears too large and very ugly. (Actually i want to arrange the things in a proper manner that it would look nice).
I have tried with "setMinimumSize" and "setSize". But it seems the grid layout is ignoring them.

Almost all layout managers ignore the value returned by getSize(). Instead they use the value returned by getPreferredSize(). getMinimumSize() and getMaximumSize() may also be used but only to determine the maximum bounds for components. You'll need to call setPreferredSize instead.

There is a but though. GridLayout uses getPreferredSize() of all the components to calculate the grid cell size. This is then the maximum of all preferred widths by the maximum of all preferred heights. So if you have another component that is longer or higher than your combo box then your combo box will still be stretched. To prevent this, either don't use GridLayout, or put the combo box in a JPanel that you put in your applet. This JPanel can keep its default FlowLayout.
 
harshi Sum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Please UseCodeTags next time. I've added them for you this time.

harshi Sum wrote:I want to set size of the "combobox" , because it appears too large and very ugly. (Actually i want to arrange the things in a proper manner that it would look nice).
I have tried with "setMinimumSize" and "setSize". But it seems the grid layout is ignoring them.

Almost all layout managers ignore the value returned by getSize(). Instead they use the value returned by getPreferredSize(). getMinimumSize() and getMaximumSize() may also be used but only to determine the maximum bounds for components. You'll need to call setPreferredSize instead.

There is a but though. GridLayout uses getPreferredSize() of all the components to calculate the grid cell size. This is then the maximum of all preferred widths by the maximum of all preferred heights. So if you have another component that is longer or higher than your combo box then your combo box will still be stretched. To prevent this, either don't use GridLayout, or put the combo box in a JPanel that you put in your applet. This JPanel can keep its default FlowLayout.



Thanks a lot. My problem solved with GridBagLayout.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the first time I've ever heard anybody say that

Not that GridBagLayout isn't a good solution, it's just not an easy one. Totally Gridbag
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic