How to write a Java application who doesn't get the focus? - java

Is it possible to write a Java application (Swing / JavaFX) who doesn't get the focus when launched? So that the application who had the focus before keeps it's focus?

Yes, sure. First if you create Window (not frame or JFrame) it does not get focus by default.
Second, just call f.setFocusableWindowState(false); on your frame and get the same behavior.

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?

Java Window in another Window

Multi-window applications often have a main-window, and all other windows are kind of 'parented' to it. Minimizing such a sub-window will hide its content and show the title-bar at the bottom-left of the screen. Also, these windows do not have their own Icon in the Task-bar, only the main-window does.
How can I make a window being attached this way to another window?
If that is possible, is it also possible without a referenfe to the actual main window?
#2: I'm embedding Java into such an application and I would like to be able to use awt or swing additionally to the native dialogs, which have this behavior by default.
See How to Use Internal Frames.
have look at JInternalFrames for MDI application
read Oracle tutorial, try code example

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.

Startup up Logo window - Swing

I have written a swing application in Java and want to display the logo of the application at program start-up for a couple of seconds before the actual program GUI appears. How do you think I can do this in swing?
A built-in Splash-Screen Functionality was added in Java SE 6, take a look here .
You can use SplashScreen: SplashScreen.getSplashScreen().setImageURL(imageURL)
If it does not meet your requirements for some reason you can either create instance of java.awt.Window or javax.swing.JWindow and put image at the middle of the window. Use Timer to disappear this window after specific timeout.
You can also use Frame or JFrame and call its f.setUndecorated(false)

Passing swing screen to another Java application. Does swing update its screen when minimized?

my question is two folds:
Can you pass the screen of one Swing application to another Java program so the latter can act as a "viewer" of the former? Perhaps by passing a buffered image? Can you do this for an existing Java application without code change? (if Swing allows getting the buffered image of any component by default)
A related question is let's say the above is possible and the Swing application is minimized but constantly changes its screen. Does Swing update its screen (perhaps buffer) so the previewer can show it appropriately? Does the OS matter in this case?
Thank you!
all swing compoments are serializable, so you can store and send any view to other application
1) You can create a BufferedImage of any Swing component. Screen Image does the work for you.
2) I've never tried it,but I don't see why your couldn't recreate the image as needed.

Categories