如何让JOptionPane对话框显示为任务栏上的任务? [英] How can I make JOptionPane dialogs show up as a task on the taskbar?

查看:198
本文介绍了如何让JOptionPane对话框显示为任务栏上的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题遵循横向规则;我自己的答案在它之前。

The question follows the horizontal rule; my own answer precedes it.


基于Oscar Reyes ,我精心设计了这个解决方案:

Based on help from Oscar Reyes, I crafted this solution:

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 解雇申请。

Notice I display my output in a JOptionPane.showInputDialog also. This way the output is highlighted in a text field so I can simply press CTRL+C to copy the output to the system clipboard and them press ESC to dismiss the application.

我为我的琐碎申请创建了一个简单的GUI。我的应用程序提示输入 JOptionPane.showInputDialog 的单个输入,执行计算,然后使用 JOptionPane.showMessageDialog 。我有时会切换到最大化的浏览器窗口或其他要复制的内容,然后想切换回我的JOptionPane对话框进行粘贴。

I've created a trivial GUI for my trivial application. My application prompts for a single input with a JOptionPane.showInputDialog, performs a calculation, and then displays a single output with a JOptionPane.showMessageDialog. I sometimes switch to a maximized browser window or something else to copy from, and then want to switch back to my JOptionPane dialog to paste into.

我想要我的JOptionPane对话框显示为任务栏上的任务,因此我可以像几乎任何其他正在运行的程序一样切换到它。我更喜欢JOptionPane的简单性,而不是必须创建JFrame,FlowLayout,Icon,JTextField,JButton,ActionListener等等。

I want to have my JOptionPane dialog show up as a task on the taskbar so I could switch to it like nearly any other running program. I prefer JOptionPane's simplicity, rather than having to create a JFrame, a FlowLayout, an Icon, a JTextField, a JButton, an ActionListener, and so on, and so on.


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

  • 如果是这样,我该如何让它出现?

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

  • Can JOptionPane show up as a task on the taskbar?
  • If so, how do I get it to show up?
  • If not, is there anything else that's a one-liner like JOptionPane.show[whatever]dialog()?

推荐答案


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


    • 如果没有,还有其他任何类似于JOptionPane的单线程.show [whatever]对话框()?

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

    Not exactly one liner ( but some extra 6 lines :P )

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

    I bet you cam put all this in a utlity method pretty easy and call it whenever you need it with a single call.

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

    The following code would add a taskbar for your app.

    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中,我可以切换到OptionPane使用Alt + Tab而没有其他任何东西(虽然我不能像你说的那样在任务栏中看到它)

    By the way in Windows Vista, I can switch to the OptionPane using Alt+Tab without anything else ( although I cannot see it in the taskbar as you said )

    这篇关于如何让JOptionPane对话框显示为任务栏上的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆