Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Component Sizes

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi! I'm trying to set a component (jcombobox) to a set size. The contents of this component change, and thus, so does the size, and I want it fixed. I tried setSize, setBounds, and setMinimumSize but they don't work. Any ideas? Thanks
 
I'm not entirely sure about wizarud's comment (apologies if oncorrect). If you ask me Swing is difficult for EASY component layout. Sometimes I've found in the past, if you dump your JComboBox in a JPanel, and then into your JFrame, and set as many bounds/constraints as possible along the way, and then hope and then pray, then it doesn't move - sometimes.
I've often got around the problem also by using BorderLayout -
eg:
JComboBox myComboBox = new JComboBox();
//whatever with JCBox
JPanel damnMovingPanel = new JPanel();
damnMovingPanel.add(myComboBox, BorderLayout.CENTER);

JFrame f = new JFrame;
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(damnMovingPanel, BorderLayout.CENTER);

This way, once your JCBox is set within the panel, within the frame, hopefully it will never move.

But I promise nothing - my luck with this kind of thing has always been severly shakey. Have a play with the LayoutManagers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top