1

I am working on a program that shows the following menu (menu_image) when it starts. I have a little problem: I'd want to show it on the top of the other windows, but I am not able to achieve this.

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

Can someone help me, please? Thank you in advance

  • Pass your main window as the first parameter instead of passing `null`. – Arnaud Apr 27 '17 at 13:04
  • Possible duplicate of [how to show JOptionPane on the top of all windows](http://stackoverflow.com/questions/10880981/how-to-show-joptionpane-on-the-top-of-all-windows) – Arnaud Apr 27 '17 at 13:11
  • 1
    Okay, I did it. Thank you for your help! –  Apr 27 '17 at 13:13

1 Answers1

4

Based on Berger's suggestion, I solved my problem in the following way...

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