How can I make JOptionPane dialogs show up as a task on the taskbar?

蹲街弑〆低调 提交于 2019-11-30 04:53:02
OscarRyz
  • Can JOptionPane show up as a task on the taskbar?

No

  • If not, is there anything else that's a one-liner like JOptionPane.show[whatever]dialog()?

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();
    }
}

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 )

This question is platform dependent. On my system, Debian Linux with OpenBox, JOptionPanes always show up on taskbar. I can't prevent any JDialog from appearing on taskbar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!