【问题标题】:Show JOptionPane (with dropdown menu) on the top of other windows在其他窗口的顶部显示 JOptionPane(带有下拉菜单)
【发布时间】:2017-09-25 07:14:31
【问题描述】:

我正在开发一个程序,它在启动时会显示以下menu (menu_image)。我有一个小问题:我想在其他窗口的顶部显示它,但我无法实现。

class Menu {
    public String showMenu(){
        Object[] options = {"option1", "option2", "option3"};
        Object selectionObject = JOptionPane.showInputDialog(null, "Choose", "Menu", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
        String selectionString = selectionObject.toString();
        return selectionString;
    }
}

有人可以帮帮我吗?提前谢谢你

【问题讨论】:

标签: java swing user-interface window joptionpane


【解决方案1】:

根据伯杰的建议,我通过以下方式解决了我的问题...

class Menu {
    public String showMenu(){
        //i solved my problem adding the following 2 lines of code...
        JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);

        Object[] options = {"option1", "option2", "option3"};
        //...and passing `frame` instead of `null` as first parameter
        Object selectionObject = JOptionPane.showInputDialog(frame, "Choose", "Menu", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
        String selectionString = selectionObject.toString();
        return selectionString;
    }
}

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    相关资源
    最近更新 更多