• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to create Jcombobox with fixed width?

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to create Jcombobox with fixed width ? (irrespective of its elements width)
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
couple of things to try

comboBox.setPreferredSize(...)
comboBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXX");
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
comboBox.setPrototypeDisplayValue(widestItem);
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Preferred size 10, 20? You are lucky to see the combo box at all when it's that small!
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
leave the size.....
let me know, whether it is possible to display the entire content or not
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam sorry for that ....
thanks for the reply...............

here is the sample code



look for the codes inside //---------------------------//
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
----------
select |
-------------------------
item1 |
item2 |
item3 |
item4 |
aaaaaaaaaaaaaaaaaaaaaaaa|
-------------------------
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply.......

SteppedCombo Box!!!

i will search for it......
 
reply
    Bookmark Topic Watch Topic
  • New Topic