Home > Java, Programming > Example Code #2 – JOptionPane JCombobox

Example Code #2 – JOptionPane JCombobox

This code shows how to add ComboBox property to JOptionPane.showInputDialog. And the class is able to take an input from this combobox

import javax.swing.JOptionPane;

public class Options {

	public Options() {

		String smallList[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
				"Thrusday", "Friday", "Saturday" };

		String value = (String)JOptionPane.showInputDialog(
				null,
				"What is your favourt day?",
				"Which day?",
				JOptionPane.QUESTION_MESSAGE,
				null, // Use default icon
				smallList,
				smallList[smallList.length-1]);

		JOptionPane.showMessageDialog(null,
				"Your favourit Day: " + value);

	}
	public static void main(String[] args) {
		new Options();
	}

}
VN:F [1.9.11_1134]
Rating: 5.0/10 (2 votes cast)
VN:F [1.9.11_1134]
Rating: 0 (from 0 votes)
Example Code #2 - JOptionPane JCombobox, 5.0 out of 10 based on 2 ratings
  1. No comments yet.
  1. No trackbacks yet.