简体   繁体   中英

How to display the input on JFrame from jOptionPane?

So I have this code.

String input;
input = JOptionPane.showInputDialog("Type words:");

How do I display the input in JFrame if this code is inside my mouseListener ?

I did not use System.out.println() because it only prints in the console.

How about this ?

String input;
input = JOptionPane.showInputDialog("Type words:");
JOptionPane.showMessageDialog(null, input);

If you really need it to be shown on a new JFrame , you can create a new JFrame and add input to JLabel ;

JFrame frame = new JFrame("The Title");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(100,100);
frame.getContentPane().add(new JLabel(input));
frame.setLocationRelativeTo(null);
frame.setVisible(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM