Unfocusable JavaFX Windows - java

I'm currently developing an application in JavaFX to create a virtual keyboard.
I had done it in Swing, and I worked with an unfocused JFrame to be able to send KeyEvent to the background application (for example Word is open, my always on top JFrame is visible, I click on a button, and it fire key event to Word).
In Swing I did:
frame.setFocusable(false);
frame.setFocusableWindowState(false);
But in JavaFX I didn't find how to do it, I saw
stage.setFocused(false);
But it's not working, is there an solution or workaround ?

Requested a feature on report board
https://javafx-jira.kenai.com/browse/RT-40494?page=com.atlassian.jira.plugin.system.issuetabpanels

Related

Way to capture events from two seperate Java Swing Application windows

I have the following simple question. Is it possible for someone to have two Java Swing application windows from which events could be captured?
I have the following scenario. I have an app which runs on a touch enabled device running Windows 7. Said app spawns another child JFrame. Now, if I click on the parent frame, I get the window's focus and I can perform actions. Doing the same on the child frame also does the same getting the focus from the parent.
What I want to do, is to be able to handle click events on both screens - that is don't block the other frame when someone is interacting with the other one.
Is there a way to do something like that?

Creating a window always focused for Windows

I am using Java to create an foreground application that uses the Robot class to send mouse clicks to other applications real-time.
Here's my issue at the moment: my application needs to read from a device in real time and keep sending Robot commands. However, mouse clicks cause the focus to be shifted to other applications. Therefore, I cannot continue reading or sending commands.
I've tried jDialog's and jFrame's setAutoRequestFocus(false) and true but I couldn't keep the window's focus.
Can anyone help me with this?

How to reopen java application launch4j single instance

Summary: make invisible app visible again by clicking desktop icon.
I have created a java desktop application and used Launch4j to create the executable. My application needs to run as a single instance. I have achieved this my checking that option in the Launch4j configuration GUI. When the user clicks the x button on my window (I'm using a JFrame) the window is made invisible. It is NOT disposed. When the user double clicks the system tray icon, the application window is made visible again. When the user double clicks the application desktop icon, and the application is already running, I need my main window to become visible again just like the behavior with the system tray icon.
Launch4j provides an option for a window title under the Single instance tab. I think that this option may be intended for what I need. However, when I set a window title and carry out the steps described above, I get a blank white window. With the blank white window displayed, double clicking my system tray icon will cause my app to appear in the white window. This behavior suggests that maybe changing my code relating to the top level container (Window,Frame,JFrame) might have an effect.
Do you have any ideas on how to incorporate this behavior while still using Launch4j? (it's convenient).
edit:
The core of my question is how do I define what happens when the user double clicks my executable desktop icon? If I could check for an existing instance and redirect the double click to the associated system tray icon, that would be fantastic.
I was able to accomplish my goal. In the Single Instance tab I gave the title of my main JFrame in the field for "Window title". I then added a WindowFocusListener to my main JFrame. When my JFrame receives focus, I check to see if it is already visible. If it is not, I call the appropriate method for displaying my JFrame.
The key observation is that double clicking the exe icon generated by Launch4j fires a window focus event when a window title is given in the setup. I am not sure if that is the only event that is fired, but by listening for that event, I can take whatever actions are necessary from within my java code when the user double clicks the desktop icon.

How to make a JFrame visible only if the control button is pressed twice

I am creating an desktop application that runs at background and while clicking the control button it should be visible i have made the setVisible(false) to the JFrame any idea how to do it . The application should triggered if you click the control button twice in desktop or in any application this should work.
This can't be done in your application.
If it runs in the background, it doesn't have the focus, so it can't react on that event. Any other application might have the focus and being interested in consuming the Ctrl button.
Think of multiple such programs, all in concurrence for that button. Which should get informed? Think of 3 Editors, all getting the next character typed.
Your OS or DE might have a way to define a hotkey, look whether your program is running (once?), and send a message to your application. The application might then react.

Opening a LWJGL window from a SWT app on Mac

I have a SWT app that opens a OpenGL window (using the LWJGL library) after a button is pressed. It is supposed to close it's main SWT window and open a new one with an OpenGL context. Works fine on Windows. On Mac, I get this error:
2010-03-05 02:28:25.315 java[1315:a07] [Java CocoaComponent compatibility mode]: Enabled
2010-03-05 02:28:25.316 java[1315:a07] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
2010-03-05 02:28:25.317 java[1315:a07] Apple AWT Startup Exception : _createMenuRef called with existing principal MenuRef already associated with menu
2010-03-05 02:28:25.318 java[1315:a07] Apple AWT Restarting Native Event Thread
The SWT window closes and then the app hangs, with no windows open.
It looks like the SWT app doesn't shut down cleanly and leaves it's menu entries associated with it, which prevents the LWJGL window from opening. Mac OS X only wants one application menu. SWT doesn't free it's own menu and LWJGL wants to add another.
Facts:
A button in the SWT dialog is supposed to close the dialog and open a LWJGL window (org.lwjgl.opengl.Display).
The button sets a static variable in the app to tell it what to do next after the SWT window is closed, so the LWJGL window is NOT being opened from a SWT callback directly.
The button then closes the SWT window. I don't know the correct way of doing this but tried various combinations of shell.close, shell.dispose, display.close and display.dispose, none of them worked. They all close the window but the error occurs every time.
Does anyone know what could be done to make this work?
UPDATE: This simply does not work and it seems that Apple will not fix it, ever. The only way around it is to launch a new app instance and pass it a parameter that tells it to open the second window.
UPDATE 2: In this particular case, I solved the problem by using the SWT dialog for the Windows version of the app and for the Mac version, I wrote a native Cocoa dialog which invokes the JVM and runs the LWJGL app when needed. That works pretty well.
It would appear to me that the problem is not SWT creating a new window or LWJGL actually doing so. I believe the problem lies in the fact that under Mac, the application menu must be registered to the process, and for some reason or another, there is a conflict of interest between the two.
You might have some better luck juggling things around a little:
What happens when you create a LWJGL window first, then create a SWT shell?
What happens when you initialize LWJGL statically before creating a SWT shell, then proceed to create the shell and create an LWJGL window?
Incidentally, to close a SWT window, all you need to do is dispose of the Shell:
shell.dispose();

Categories