By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,542 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,542 IT Pros & Developers. It's quick & easy.

size of JComboBox

P: 39
Hi, I am developing an application for which I need to increase the size of the JComboBox.But it is not getting increased.I used the following technique:

Container cont;
JComboBox valueTypeBox ;
valueTypeBox = new JComboBox();

valueTypeBox.addItem("asia");
valueTypeBox.addItem("india");

cont = getContentPane();
GridBagLayout theLayout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
JPanel hostPanel = new JPanel();
hostPanel.setLayout(theLayout);
c.gridx = 2;
c.gridy = 3;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.fill = GridBagConstraints.NONE;
c.weightx = 1;
c.weighty = 0;
c.insets = new Insets(10, 0, 0, 40);
hostPanel.add(valueTypeBox,c);

Please suggest as how can I increase the size of the JComboBox.Thanks for help.

Jerico
Nov 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: 35
We have two method called setPreferedSize(int,int) and setMinimumSize(int,int) . try this it may solve your problem
Jan 4 '07 #2

Soujiro
P: 35
The size of JComponents depends on the Layout specified by the container.. In order to change sizes and even locations you need to implement LayoutManager and do it as you want.. here is a snippet of it.


Expand|Select|Wrap|Line Numbers
  1. container.setLayout(new CustomLayout);
  2.  
  3.     public void layoutContainer(Container parent) {
  4.         Insets insets = parent.getInsets();
  5.  
  6.         Component c;
  7.         c = parent.getComponent(0);   /* the first component you add into the container */
  8.         if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+24,480,248);} /* its location and size */
  9.     }
  10.  
Jan 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.