wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes how to create Jcombobox with fixed width? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to create Jcombobox with fixed width?" Watch "how to create Jcombobox with fixed width?" New topic
Author

how to create Jcombobox with fixed width?

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
how to create Jcombobox with fixed width ? (irrespective of its elements width)


Abhishek
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
couple of things to try

comboBox.setPreferredSize(...)
comboBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXX");
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...

Its working, but the contents of the JComboBox are partially visible, is there any way to display the whole content...
I mean JComboBox width is fixed but its content should expand w.r.t contents length
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
comboBox.setPrototypeDisplayValue(widestItem);
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...i have done this way
comboBox.setPreferredSize(new Dimension(10,20))
comboBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

but still the content is not visible completely..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Preferred size 10, 20? You are lucky to see the combo box at all when it's that small!
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
leave the size.....
let me know, whether it is possible to display the entire content or not
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
comboBox.setPreferredSize(new Dimension(500,25));
OR//<---------------
comboBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

either, in conjunction with using a layoutManager, and both work fine

if they still don't work for you, post your code
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Originally posted by Abhishek Reddy:
leave the size.....
let me know, whether it is possible to display the entire content or not


Abhiskek,

I don't think that was really nice on your part.
I understand, you might be rushed to get this thing done, or frustrated at not getting it right on your own, inspite of numerous attempts; all of us have been through that phase.

However, you need to remember, statements like these, might make people think twice before helping you out in the future. You need to be careful about such things buddy


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
iam sorry for that ....
thanks for the reply...............

here is the sample code



look for the codes inside //---------------------------//
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
your problem is probably GroupLayout (which I don't use, and can't compile your code to confirm)

here's your code, stripped of all unnecessary stuff, leaving the frame as a default Borderlayout.

I've added another combobox (no prototype display), just for comparison,
and added a few extra XXX's to make it stand out


compile/run the code, note the differing widths, then comment out the
setPrototypeDisplayValue line,
recompile/rerun and you'll notice the 'aaaaaa...' item fully displayed,
so it does appear GroupLayout is causing all your problems
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks...for the reply
i have understood the usage of setPrototypeDisplayValue(prototypeValue);

But i want to display the JComboBox in the following way

----------
select |
-------------------------
item1|
item2|
item3|
item4|
aaaaaaaaaaaaaaaaaaaaaaaa|
-------------------------
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
----------
select |
-------------------------
item1 |
item2 |
item3 |
item4 |
aaaaaaaaaaaaaaaaaaaaaaaa|
-------------------------
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
OK, I think I know what you really want now.

search the sun forums and google for SteppedComboBox,
it matches exactly your description.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply.......

SteppedCombo Box!!!

i will search for it......
 
 
subject: how to create Jcombobox with fixed width?
 
Similar Threads
How to keep formatting while reading files
JComboBox
JComboBox's Scrollbar - increasing width
how to create fixed width text file.
pop-up window(not pop-up menu)