编辑:
问题遵循横向规则;我自己的答案先于它.
根据Oscar Reyes的帮助,我制定了这个解决方案:
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class MyApp extends JFrame {
public static void main(String [] args) {
new MyApp();
}
public MyApp() {
super("MyApp");
setUndecorated(true);
setVisible(true);
setLocationRelativeTo(null);
String i = JOptionPane.showInputDialog(this, "Enter your name:", getTitle(), JOptionPane.QUESTION_MESSAGE);
if(null != i) {
JOptionPane.showInputDialog(this, "Your name is:", getTitle(), JOptionPane.INFORMATION_MESSAGE, null, null, i.concat(i));
}
dispose();
}
}
注意我也在JOptionPane.showInputDialog中显示我的输出.这样,输出在文本字段中突出显示,因此我可以简单地按CTRL C将输出复制到系统剪贴板,并按ESC键关闭应用程序.
我为我的微不足道的应用程序创建了一个简单的GUI.我的应用程序使用JOptionPane.showInputDialog提示单个输入,执行计算,然后使用JOptionPane.showMessageDialog显示单个输出.我有时会切换到最大化的浏览器窗口或其他要复制的窗口,然后要切换回我的JOptionPane对话框进行粘贴.
我想让我的JOptionPane对话框显示为任务栏上的任务,所以我可以像几乎任何其他正在运行的程序一样切换到它.我更喜欢JOptionPane的简单性,而不是创建一个JFrame,一个FlowLayout,一个图标,一个JTextField,一个JButton,一个ActionListener等等.
> JOptionPane可以显示为任务栏上的任务吗?
>如果是这样,我该如何让它出现?
>如果没有,还有其他一些像JOptionPane.show [whatever] dialog()的单行吗?