get Input from Swing JOptionPane - Java Swing

Java examples for Swing:JOptionPane

Description

get Input from Swing JOptionPane

Demo Code


//package com.java2s;

import javax.swing.JOptionPane;

public class Main {
    public static String getInput(String msg, String defaultInput) {
        // msg = something like: "Please enter the MTP directory, e.g., '/sdcard/Music'"

        String input = (String) JOptionPane.showInputDialog(msg,
                defaultInput);// w w w.ja  v  a2 s.  co m

        return input;

    }

    public static String getInput(String msg, String[] options,
            String defaultInput) {
        // msg = something like: "Please enter the MTP directory, e.g., '/sdcard/Music'"

        String input = (String) JOptionPane.showInputDialog(null, msg,
                "Please select an option", JOptionPane.PLAIN_MESSAGE, null,
                options, defaultInput);
        return input;

    }
}

Related Tutorials