ele*_*n81 17 java user-interface swing taskbar 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();
}
}
Run Code Online (Sandbox Code Playgroud)
注意我也在JOptionPane.showInputDialog中显示输出.这样输出在文本字段中突出显示,因此我只需按CTRL+ C即可将输出复制到系统剪贴板,然后按下ESC以关闭应用程序.
我为我的琐碎应用程序创建了一个简单的GUI.我的应用程序提示单个输入a JOptionPane.showInputDialog,执行计算,然后用a显示单个输出JOptionPane.showMessageDialog.我有时会切换到最大化的浏览器窗口或其他要复制的内容,然后想切换回我的JOptionPane对话框进行粘贴.
我希望我的JOptionPane对话框显示为任务栏上的任务,因此我可以像几乎任何其他正在运行的程序一样切换到它.我更喜欢JOptionPane的简单性,而不是必须创建JFrame,FlowLayout,Icon,JTextField,JButton,ActionListener等等.
JOptionPane.show[whatever]dialog()吗?Osc*_*Ryz 22
没有
不完全是一个衬垫(但有一些额外的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();
}
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,在Windows Vista中,我可以使用Alt + Tab切换到OptionPane,而不是其他任何东西(虽然我不能像你说的那样在任务栏中看到它)
| 归档时间: |
|
| 查看次数: |
9035 次 |
| 最近记录: |