JOptionPane.showInputDialog

A

Arun

I have a showInputDialog that takes an array of strings and creates an
option box from which to select a certain option.

However i want the dialog to also allow the user to input a string if
they so wish.

JavaDoc:(http://java.sun.com/j2se/1.4.2/docs...g.Icon, java.lang.Object[], java.lang.Object))



The javadoc says "The user will able to choose from selectionValues,
where null implies the user can input whatever they wish, usually by
means of a JTextField. "

I have tried adding null in the array but i cant enter anything.
Does anyone know how to do this?
 
A

Arun

I know realise that the JavaDoc meant adding null as a parameter to the
showInputDialog will allow user input.

Is there anything that will allow user's to select an input or input
anything else if they so wish?
 
A

Arun

I now realise that adding null meant adding it as a parameter to the
showInputDialog.

Is there any dialog that will allow the user to both select or input a
new input?
 
A

Andrew Thompson

Is there anything that will allow user's to select an input or input
anything else if they so wish?

<sscce>
import javax.swing.*;

/** Displays an editable JComboBox in a JOptionPane to obtain
'list' or new data from the user. */
public class JComboOptionPane {

public static void main(String[] args) {
String[] list = {"Banana", "Apple", "Pear", "Grape"};
JComboBox jcb = new JComboBox(list);
jcb.setEditable(true);
JOptionPane.showMessageDialog( null, jcb,
"select or type a value", JOptionPane.QUESTION_MESSAGE);

JOptionPane.showMessageDialog( null,
new JLabel( "User selected: " + jcb.getSelectedItem() ) );
}
}
</sscce>

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top