How can I gain focus on JME Application window?

I am new to JMonkey and I’m looking to gain focus on the JMonkey window that I have that hosts various jme content. Typically, I can do this by calling something like frame.toFront() then frame. repaint().



How would I gain control of the actual hosting frame for a JMonkey application, and thus, bring it to the front or gain focus on this window once it is lost? I’ve searched through the API with little results for anything close. There is a “GainFocus” method that can be called, but it does not appear to do anything and is marked in the docs as “internal use only.”



Thoughts?

Its not a swing window, use awt panels or the canvas implementation if you want more control over the window.

Is this possible using the nifty display components? Either NiftyJMEDisplay or NiftyDisplayProvider? Rewriting the app for awt panels or canvas isn’t an option at this time.

rewriting? you just need to use it instead of the normal window… oO anyway with nifty you can also have multiple windows or panels yeah. I don’t know what you want to do so i cannot say exactly.

Currently this app doesn’t use a canvas, frame, or window. If it did, I would just access that. The primary display type is NiftyJmeDisplay.



All I want to do is gain control of the jmonkey app window so I can re-focus this if focus is lost without having to have the user click back on the app window.

@jmenewb said:
All I want to do is gain control of the jmonkey app window so I can re-focus this if focus is lost without having to have the user click back on the app window.


So what you're saying is that if I run your game or app windowed and want to chat with a friend of mine on steam or I want to check a website at the same time, you won't allow that? Really?

And it also goes without saying that this is extremely rude and bad ethics. If it's settings-based I wouldn't object to it as long as it would be disabled by default, but except for that, there should be a law against this.

Note to self: do not play with jmenewb's game or app if that feature is implemented.

No. I am launching my app via JNLP web start. If someone was to launch two instances of this app, I want the second instance to not start, and the first running instance to come back in to focus. I already have the instancing here taken care of. I’m looking to obtain control over this window once it is lost.



As far as the rest of your comments, I won’t bother with a response.

Put it any way you want it’s hijacking. That you check for multiple instances is fine and should be commanded, but don’t force the focus. Just give the user an “error” message. You don’t need to do more.

@madjack said:
Put it any way you want it's hijacking. That you check for multiple instances is fine and should be commanded, but don't force the focus. Just give the user an "error" message. You don't need to do more.


Madjack. Are you planning on actually contributing anything to this thread? I don't need a lesson in game design, user interfaces, nor "hijacking" from you. If you can't respond to the question I asked about initially, why are you posting here?

Sensitive much? :cry: a little more. I like the rage. Down-vote me as much as you like, it won’t make your game user-friendly.

2 Likes

You could check if the app is already running in the main method before you actually start jme, then no window will pop up. But if you have already lost focus of the app by launching the webstart link again then you might not be able to get focus back easily… or it could end up being a little hostile and act differently on the different OS’s.

I can’t quite picture your use-case, any more details or a picture to help?

Sploreg,



Here is the use case.



Currently I’m using JMonkey to display various information/models that the user requests. The app itself is launched via web start. The user can click the web start link multiple times and it will not spawn multiple instances of the app. It will however open a web page and lose focus to the app that is already running. All I’m looking to do here it to bring focus back to the previously launched application. Again, in the past, I’ve used frame.toFront() with a repaint, and that has worked. Being that this app was written using SImpleApplication/Application/Nifty, I’m looking for similar functionality without having to rewrite the entire app as it stands.

Hmm, yea it might just be easier to use the jme canvas in swing, then you can have more control over the window, focus, etc.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:swing_canvas

1 Like

Hmm, okay. I was hoping I wouldn’t have to rewrite what was here, but that might be the only option. Thanks for the link.

@jmenewb said:
Hmm, okay. I was hoping I wouldn't have to rewrite what was here, but that might be the only option. Thanks for the link.

:? I still don't know about what "rewrite" you are talking. Your application and all code stays the same, you just initialize the application differently and create an awt window before.

@jmenewb: What you’re trying to do is impossible. jME3 doesn’t have control over the window, LWJGL does. Currently the LWJGL API does not provide the capability to focus onto the window, so it cannot be done.

1 Like