Probleme bei der Konfiguration von JOptionPane

Hi Leute,

ich hätte da mal eine Frage zur Klasse JOptionPane.

Und zwar sollte hier im Falle, das der DialogType INPUT_DROPDOWN ist, ein JOptionPane mit Dropdown - Menü erscheinen. Wenn ich diesen Code aber ausführe, bekomme ich ein Fenster, das genau wie der Standard aussieht… Kann mir jemand sagen warum?

Vielen Dank!


import javax.swing.JOptionPane;

public class KapaGui extends JOptionPane {

	private String input = "";

	public KapaGui(DialogType dialogType, String description) {
		if (dialogType == DialogType.INPUT) {
			this.input = this.showInputDialog(description);
		} else if (dialogType == DialogType.INPUT_DROPDOWN) {
			String[] array = new String[] { "a", "b", "c" };
			this.input = (String) this.showInputDialog(null, description,
					"Show Database Table", 4, null, array, "1");
		} else if (dialogType == DialogType.CONFIRM) {
			this.showConfirmDialog(this, initialSelectionValue);
		}
	}

	public String getInput() {
		return this.input;
	}

}

Gruß
G@st

Der Messagetyp 4 ist falsch. Da bekomm ich sogar ne Exception. Regel das anstatt mit Zahlen lieber über die dafür vorgesehenen Type- Konstanten:

ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_MESSAGE

MMn bringt es nichts das JOptionPane zu überschreiben, man kriegt so ziemlich alles hin wenn man auf die statischen showXXXDialog Funktionen zurückgreift. Für einfache Ein/Ausgaben reichts sowieso, für was komplexeres kann man sich einfach ein Panel zusammenbauen und das dann der Funktion übergeben.
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

Hier ein Beispiel:



public class SpinnerInOptionPane extends JFrame {

	private JPanel contentPane,labelPane;
	private JPanel spinnerPanel;
	private JSpinner spinner1,spinner2;
	private JLabel label1,label2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SpinnerInOptionPane frame = new SpinnerInOptionPane();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SpinnerInOptionPane() {
		spinner1=new JSpinner();
		spinner2=new JSpinner();
		spinnerPanel=new JPanel();
		spinnerPanel.add(new JLabel("Spin 1:"));
		spinnerPanel.add(spinner1);
		spinnerPanel.add(new JLabel("Spin 2:"));
		spinnerPanel.add(spinner2);
		
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		labelPane=new JPanel();
		label1=new JLabel();
		label2=new JLabel();
		labelPane.add(label1);
		labelPane.add(label2);
		
		contentPane.add(labelPane,BorderLayout.NORTH);
		
		JButton btnShowDialog = new JButton("Show Dialog");
		btnShowDialog.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				int returnValue=JOptionPane.showConfirmDialog(SpinnerInOptionPane.this, spinnerPanel,"Daten eingeben",JOptionPane.OK_CANCEL_OPTION);
				if(returnValue==JOptionPane.OK_OPTION)
				{
					label1.setText(spinner1.getValue().toString());
					label2.setText(spinner2.getValue().toString());
				}
			}
		});
		contentPane.add(btnShowDialog, BorderLayout.SOUTH);	
			
	}

}