Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with JOptionPane Combobox max rows or height

 
B. Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, all! I'm trying to get a JOptionPane message to display a combo box to select options from, as follows:



The problem is that unlike a manually coded combo box, I have no way to set the maximum row count, as I normally would like this, nor can I make the combo box taller to display more rows at a time as I normally would. The result is a one-line high listbox with a very tiny scroll-bar with over a hundred values in it, which, of course, would be a pain for the end user.

What are my options?

Thanks,

~B. Smith
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

JOptionPane#showInputDialog also accepts an Object message.
Set up your JComboBox as you like it and pass it as the message.
 
Rob Camick
Ranch Hand
Posts: 2555
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine for me using JDK6_7 on XP.

It shows the list with 10 rows:



Post your SSCCE that demonstrates the problem. Maybe its a platform or LAF issue?
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Welcome to the Ranch.

JOptionPane#showInputDialog also accepts an Object message.
Set up your JComboBox as you like it and pass it as the message.

Or a JList wrapped in a JScrollPane.
 
B. Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies for the late reply. I am trying to make the SSCE, but removing all "superfluous" code seems to solve the problem. It works in the SSCE I almost posted, giving me a decently tall listbox when I pass in an array of a hundred strings, but in my actual code, it still presents a listbox one entry high. I am now thoroughly confused. When I am able to narrow my problem down to another specific question, I will be back and post in this thread again. Sorry to be a bother.
 
Rob Camick
Ranch Hand
Posts: 2555
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The is the point of a SSCCE. Do a simple case and compare to the more complex case. Most times you will find the problem.
 
B. Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I found out what the cause was, but I must admit, the behavior is quite odd and confusing.



Apparently, the problem is caused when the first element in the list is an empty string. If you run the above code, you will notice that the first option pane works fine, but the second, with the blank value at the top, causes the list to "shrink" to a single value. This is confusing.

In my project, I can omit the empty string at the beginning of the list. That's not a huge problem. I was going to use it, but there's a workaround I think I could implement. Now, I'm just mystified. Is there anybody here who can explain why this happens, so I can know for next time?
 
Rob Camick
Ranch Hand
Posts: 2555
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess an empty string doesn't have a size which is somehow used by the list renderers. Just make is a string with blanks:



Also, don't mix AWT components in a Swing application. Use a JButton.
 
B. Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Thank you so much for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic