Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing JOptionPane showInputDialog : own textfield or combobox

 
Alex Iordache
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading the API of JOptionPane in the most parameters showInputDialog (see copy below), at the end I
read :
It is up to the UI to decide how best to represent the selectionValues, but usually a JComboBox, JList,
or JTextField will be used.
Now in a JCombobox you are sure only one value is selected, in a list you can select more.
How can I make sure :
that I have a combobox,
or in case I will get a list, that only one value can be selected?
General idea is : how to make sure there is only one selection possible?
Please add codesnippit,
Thanks,
javabit
showInputDialog
public static Object showInputDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon,
Object[] selectionValues,
Object initialSelectionValue)

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and
all other options can be specified. The user will able to choose from selectionValues, where null implies
the user can input whatever they wish, usually by means of a JTextField. initialSelectionValue is the
initial value to prompt the user with. It is up to the UI to decide how best to represent the selectionValues,
but usually a JComboBox, JList, or JTextField will be used.
An example will help me very much. Thanks.
 
Fatos Maxhuni
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I ma not sure if I understood this question but to make sure
that you get a single value from a JList you can set the a a SINGL selection mode, i.e.
someList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Originally posted by Alex Iordache:
Reading the API of JOptionPane in the most parameters showInputDialog (see copy below), at the end I
read :
It is up to the UI to decide how best to represent the selectionValues, but usually a JComboBox, JList,
or JTextField will be used.
Now in a JCombobox you are sure only one value is selected, in a list you can select more.
How can I make sure :
that I have a combobox,
or in case I will get a list, that only one value can be selected?
General idea is : how to make sure there is only one selection possible?
Please add codesnippit,
Thanks,
javabit
showInputDialog
public static Object showInputDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon,
Object[] selectionValues,
Object initialSelectionValue)

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and
all other options can be specified. The user will able to choose from selectionValues, where null implies
the user can input whatever they wish, usually by means of a JTextField. initialSelectionValue is the
initial value to prompt the user with. It is up to the UI to decide how best to represent the selectionValues,
but usually a JComboBox, JList, or JTextField will be used.
An example will help me very much. Thanks.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic