Java: editable JCombobox in JOptionPane inputDialog?

Following the example here is http://www.java2s.com/Code/JavaAPI/javax.swing/JOptionPaneshowInputDialogComponentpObjectmStringtintmIconiObjectoObjecti.htm

Is there any way to make jcombobox by default editable? It seems that there is no JCombobox instance in JOptionPane, is it possible to extend and override the default JCombobox used by JOptionPane?

+4
source share
1 answer

You can do this with showMessageDialog() by creating a JComboBox and converting it to editable using setEditable() .

Example:

 String[] list = {"A", "B", "C"}; JComboBox jcb = new JComboBox(list); jcb.setEditable(true); JOptionPane.showMessageDialog( null, jcb, "select or type a value", JOptionPane.QUESTION_MESSAGE); 

You can get the value in JComboBox with:

 jcb.getSelectedItem() 
+10
source

Source: https://habr.com/ru/post/1399243/


All Articles