custom input dialogs

JOptionPane is very easy to use. You can even pass your own JPanel to display on the dialog. This way you can easily retrieve user input. An example:

TerminologyVersionPanel panel = new TerminologyVersionPanel();
int answer = JOptionPane.showConfirmDialog(
parentComponent, panel, title, JOptionPane.OK_CANCEL_OPTION,
if (answer == JOptionPane.YES_OPTION){
// do stuff with the panel
System.out.println("your input: "+panel.getVersion()+" "+panel.getDate());
//otherwise input has been canceled

and an example for the panel

public class TerminologyVersionPanel extends JPanel {

* txtfield for the version name
private JTextField txtVersion;

* datepicker for releasedate
private JXDatePicker datePicker;

* def ctor
public TerminologyVersionPanel() {

private void init() {
// set layout here
setLayout(new GridLayout(0, 2));

// string title
add(new JLabel("version name"));
txtVersion = new JTextField();

// datepicker
add(new JLabel("release date"));
datePicker = new JXDatePicker();

// getters to retrieve input

public String getTxtVersion() {
return txtVersion.getText();

public Date getDate() {
return datePicker.getDate();



Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait