aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem in Changing size of JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in Changing size of JComboBox" Watch "Problem in Changing size of JComboBox" New topic
Author

Problem in Changing size of JComboBox

harshi Sum
Greenhorn

Joined: Jan 18, 2011
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
harshi Sum
Greenhorn

Joined: Jan 18, 2011
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Changing size of JComboBox