如何让JOptionPane对话框显示为任务栏上的任务?

编辑:

问题遵循横向规则; 我自己的答案先于它。

在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,Icon,JTextField,JButton,ActionListener等等。

  • JOptionPane可以在任务栏上显示为任务吗?
  • 如果是这样,我该如何让它出现?
  • 如果没有,还有其他什么是JOptionPane.show[whatever]dialog()JOptionPane.show[whatever]dialog()

  • JOptionPane可以在任务栏上显示为任务吗?

没有

  • 如果没有,还有其他什么是单线像JOptionPane.show [whatever]对话框()?

不完全是一个class轮(但有一些额外的6行:P)

我敢打赌,你可以轻松地将所有这些放在一个非常简单的方法中,只需一次通话即可随时调用它。

以下代码将为您的应用添加任务栏。

 import javax.swing.JFrame; import javax.swing.JOptionPane; public class OptionTest { public static void main ( String [] args ) { JFrame frame = new JFrame("My dialog asks...."); frame.setUndecorated( true ); frame.setVisible( true ); frame.setLocationRelativeTo( null ); String message = JOptionPane.showInputDialog(frame, "Would this be enough?.", "My dialog asks....", JOptionPane.INFORMATION_MESSAGE); System.out.println( "Got " + message ); frame.dispose(); } } 

顺便说一下,在Windows Vista中,我可以使用Alt + Tab切换到OptionPane,而不是其他任何东西(虽然我不能像你说的那样在任务栏中看到它)

这个问题取决于平台。 在我的系统上,带有OpenBox的Debian Linux,JOptionPanes总是显示在任务栏上。 我无法阻止任何JDialog出现在任务栏上。