• Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox too short

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have an application that uses a JComboBox in a BorderLayout (WEST). The trouble is: the width of the combo isn't quite wide enough on Windows. Looks fine on the MAC, but for some reason on Windows, the combo is a bit too short and I get '...' for slightly longer selected items.

Is there a way to give it a bit more width?

Cheers,

Steve
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like the container it is in doesn't have enough width to display it. Components added to the sides in a BorderLayout will be truncated when it does not have enough room to display everything. You can increase it's size in two ways. First, you can make it's parent container bigger. Second, you can change the layout behavior by changing the LayoutManager. Making the parent container bigger may require making it's parent bigger and so on all the way up the containment heirarchy, or changing the behavior somewhere along the containment heirarchy such that more space is assigned to the parent container. So, for example, if you're adding this to a JFrame's contentPane you would either make the JFrame larger or change the LayoutManager to one that will assign more space to your JComboBox.

It's also possible there's a completely different reason for this, in which case I've been no help! Good luck.
 
Ed Ewing
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some cases, JComboBox.setPrototypeDisplayValue() can be helpful. It depends on the LayoutManager and the size of the display area whether this will have any affect, but you may want to try it.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,

Just a tip for the future - Publishing the code you are having trouble with helps other people to help you. It may not have been necessary in this case but could save time in other situations.

Hope the suggestions above help you out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!