简体   繁体   English

如何从jOptionPane在JFrame上显示输入?

[英]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 ? 如果此代码位于我的mouseListener如何在JFrame显示输入?

I did not use System.out.println() because it only prints in the console. 我没有使用System.out.println()因为它仅在控制台中打印。

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 ,则可以创建一个新的JFrame并将input添加到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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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