I am trying to create a JWindow that sits on top of an external application.
I want the window to resize whenever the external application resizes (to match it) and be only on top of the external application and not everything else. (I can't use setAlwaysOnTop(), because it would be always on top of everything).
By modifying code from the first answer from here I am able to find the external window title (for example Untitled - Notepad) and its handle if needed.
Using code from the first answer from here, I can get the dimensions of an external window from it's window title.
The problem with finding the dimensions from the code at the second link is that I have to always loop and check them (which is not optimal) and it isn't helpful in putting my window only on top of the external one.
Is there a way to implement what I want in Java? Ideally, I would (using JNA?) make a listener to the messages (WinEvents?) the OS sends to the external program to resize it, gain/lose focus etc and handle them somehow.
Related
I want to emulate the ignoresMouseEvents functionality offered in Swift but using Java Swing (because I want to make an application that works at least on the most popular OS), that is, make a clickable through window (I know that functionality is used in Hellium (for mac)).
I want to basically create a semi transparent overlay showing some statistics while allowing the user to keep using his underneath programs, games, etc.
Related question in swift language: How to create a topmost overlay which ignores mouse clicks, etc
IgnoreMouseEvents property: (https://developer.apple.com/documentation/appkit/nswindow#//apple_ref/occ/instm/NSWindow/setIgnoresMouseEvents:)
I'm writing some code in Java that needs to show file chooser and alert dialogs. These dialogs always need to show up on a second monitor, rather than the main monitor.
If the application were entirely written in Java/Swing, these dialogs would be positioned relative to the application's main JFrame, and so would show up on the second monitor if that was the location of the main frame. In this application, however, the main window is created by native code. So Java doesn't know the location of the main window, and can't position its dialogs relative to it.
Is there a way that I can tell Java to show dialogs on the second monitor by default? (perhaps by changing some of the Look and Feel?)
"In a multi-screen environment, the GraphicsConfiguration objects can be used to render components on multiple screens."—GraphicsDevice. See also the Full-Screen Exclusive Mode API tutorial.
The goal is to have the user select a java program, then my program opens up a JInternalFrame with a JEditorPane inside it as the console and places said JInternalFrame in a JDeskopPane. Is it possible to change all the Windows the user's program may open into JInternalFrames and place them in said JDesktopPane, as well?
(individual question from IDE-Style program running)
I'm quite sure that this would not be possible to do without tampering with the binaries of the program that you're launching. If the target program performs something like new Window().show(), you'll have little possibilities to "hook into" the system, and tell it to swap it for a JInternalFrame.
What I'm saying is that if the program is written and compiled to show a top-level window, there is little you could do to change that. There is no "hook" into the system, with which you can say "put all future Windows into this JInternalFrame.
I'm trying to create a java desktop application that holds desktop icons. The app will be a menu/panel that is invisible until you hover your cursor near the top of the screen, at which point the menu full of desktop icons will drop down. To add new icons to the menu one must simply drag icons from the desktop into the menu and they should snap to grid. As I am an intermediate level programmer but I havn't ever done a GUI app before in any language, I was wondering if someone could help me out, both with how to approach the problem and on the packages and methods I should be using. Also, I'm thinking of doing this with NetBeans unless you have any other suggestions.
Thanks,
Andrew
As an alternative to Chad's option, you could also do this by creating a frame and using Java's transparent window capability to make the frame transparent (or translucent, if you want a hint that it's there), and using mouse entered/exited events to return the frame to its normal "solid" opacity.
Personally I'd try this solution just because I'd rather use event-based notification than polling the mouse position, but I expect it's more work than the other alternative.
As to drag and drop, I haven't used it extensively enough in Java to give any solutions, but it's not immediately obvious (from a cursory internet search) of how to handle native desktop drag and drops. I'd suggest starting with some dnd tutorials within an application so that you really understand Java's drag and drop API and capabilities.
You can use java.awt.MouseInfo to get the location of the mouse at any point in time, even if you don't have any windows open.
So, you could start a java program, then in your main loop poll the mouse location. If it's in the 'top', then you can open a window.
You can use the easiest thing to do would be to use JButtons or JLabels with images to represent the desktop icons. Just load the image you want to use and stick that on as a label.
I'd start by going through swing tutorial and writing a few simple GUI programs to get the hang of it.
But the MouseInfo thing is what you need to tell when the mouse is at the top of the screen.
I am developing a screen capturing utility in Java & I want to capture any background window, when I click on that particular window. But I am not getting how to add mouseClicked event to background window. Can somebody please help me?
I may be way off base but if the other window is not a Java window then it should be outside the Java sandbox. To interact with it requires a native API which is anathema to Java.
Quite obviously as it is you can't interact with other application windows. It can be any random window in your case I presume. Therefore, your mouselistener approach is not correct.
Rather, try to approach it like fetching pixel information displayed on the screen. There is an awt package java.awt.Robot or something that could be used for your purpose. If you want to implement capturing of active window then see if there are java APIs to interact with O.S. and get information of current active window and it's pixel co-ordinates. The co-ordinates could then be supplied to the rectangle attribute that is used with java.awt.Robot APIs to define screen capture area.
If that window is not part of your application you can't do much with it.
Otherwise you just have to add the mouse listener to that window too.
What's your situation?
java.awt.Robot has a method createScreenCapture(Rectangle screenRect) to capture screenshots.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html
however, to get the current active window you would have to use OS specific extensions (mostly via JNI)