2017-04-27 1 views
0

Ich arbeite an einem Programm, das beim Start menu (menu_image) anzeigt. Ich habe ein kleines Problem: Ich möchte es auf den anderen Fenstern zeigen, aber ich kann das nicht erreichen.Zeige JOptionPane (mit Dropdown-Menü) über anderen Fenstern

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

Kann mir bitte jemand helfen? Vielen Dank im Voraus

+0

Fahren Sie mit Hauptfenster als ersten Parameter statt vorbei 'null'. – Berger

+0

Mögliches Duplikat von [wie JOptionPane über allen Fenstern angezeigt wird] (http://stackoverflow.com/questions/10880981/how-to-show-joptionpane-on-the-top-of-all-windows) – Berger

+1

Okay, ich habe es getan. Danke für Ihre Hilfe! –

Antwort

0

Basierend auf Bergers Vorschlag, löste ich mein Problem in der folgenden Art und Weise ...

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