How am i supposed to use modal dialogs with the Swing stuff inside JME?
Cuz i need some MessageDialog my first intention was to use JOptionPane.showMessageDialog and gave it the desktopPane as JComponent. The Dialog shows up, but in an own JFrame outside the whole JME App. I didnt see it first, until i switched to a lower resolution.
JOptionPane.showInternalMessageDialog doesnt even show up.
Tried both in our app and the TestJMEDesktop.
Any ideas?
Greetz,
Azarai
Try using a JInternalFrame instead
Not sure what you meant. But JOptionPane.showMessageDialog giving a JInternalFrame instead of the desktopPane ends in the same result. MessageBox appears, but ouside the app.
And using a JInternalFrame as the MessageDialog does not fit the requirement of a modal dialog. I found some stuff on sun site to get JInternalFrame modal, buts not working in jme. Nothings pops up at all and app freeze of "unvisible" modal dialog.
The Swing test shows how to create JInternalFrames…follow that and you'll at least get them to pop-up.
darkfrog
I know that JInternalFrame works with jme,this was not my question. I had a problem with JOptionPane and modal dialogs and just adding an JOptionPane on a JInternalFrame solves not my problem of getting a modal dialog. Back to my original question "how do i get a modal swing dialog inside jme?"
Do you have other dialogs that you are wanting to keep from being accessable? If you just use a glasspane on the rest of your desktop when the JInternalFrame is up it should solve that problem. I guess the question is, what functionality do you want from a modal dialog? I have seen some issues trying to deal with dialogs in jME as the JFrame is not really there. :o
darkfrog
Ok, I'll try to reduce the confusion here a bit:
A modal dialog as known from swing would be a separate window that is displayed above a dialog/frame/applet. It prevents the rest of the gui to be accessible while it is shown.
This is obviously not the thing somebody wants in a game when using JMEDesktop as the 'dialog' should appear in the game window not in a separate one.
The effect you'd need for JMEDesktop is preventing input to reach other components while an internal window is shown. Neither JOptionPane.show… nor JOptionPane.showInternal… is suited for that purpose as both block the swing thread and thus the jme thread. At this time you have to come up with an own solution.
As darkfrog suggested you can prevent input to other components by adding an invisible component above all other components on the desktop and only one internal frame above the invisible component to show your option pane (which can be created by new JOptionPane(…)).
As I don't like modal dialogs jME does not have support for it yet. But if you come up with a good solution it could be included.
Ok, right now i have a JPanel centered on my screen as a mainmenu. If during eg login an error occured, i'd like to pop up a message dialog with some informations and until the user clicks the ok button, the JPanel shouldnt accept any input. Same stuff i'd need later on too. So after the JOptionPane.show… solution was not working i already tried to create the interalFrame myself with and via the JOptionPane. Its showing up nicely, but is hidden behind my menu JPanel. No luck yet to get it in front.
Also i tried yesterday with the glasspane, but desktopPane has not JRootpane. Not sure about if it works if i just use a JInternalFrame on the desktopPane and put all my stuff on the internalFrame. Didnt really like this idea.
I know the JOptionPane.show… blocks the other threads, but at current stage i didnt really care and just tried the easiest swing solution
You can use jmeDesktop.setFocusOwner(yourInternalFrame) as requestFocus and grabFocus don't work inside of jME. Also, you can set the glasspane on your internal frame so that nothing else can be clicked while it is open.
I'm still having some trouble getting everything to work for me as well, so don't feel bad. :o
darkfrog
Got a working solution now. But first some infos, that others can avoid this pitfall
- Dont use any of the JOptionPane show methods
- The createInternalFrame doesnt work either, not sure why, but it does some initialization that doesnt work and shows the internalFrame always behind the JPanel
- The glassPane is always inside your internaleFrame Message Dialog and the rest outside is still accessible. Maybe a JRootpane on the desktopNode would solv it, *hint* :)
What i am doing now is creating my internal frame, adding a JOptionPane, registering a propertyChangeListener to the option pane and put that frame into the desktopPane at layer 255. All Components below this layer get programmatically disabled.
If user clicks on the ok button, i enable all components again.
Oy, we've got to get a better method than having to do that. :o
darkfrog
I've added support for it directly in JMEDesktop - see TestJMEDesktop.showDialog() for an example