I'm using JNativeHook to detect drags and clicks outside a JFrame in my program and it's running perfectly. The thing is I need a way (either using JNativeHook or anything else) to check if a folder is opened in my explorer (Finder for Mac) so that I can move a file to this opened folder. JNativeHook doesn't seem to have the option of detecting on what program or window was the click made.
I expect the output of the code I'm looking for to return the path of open folders in my system explorer so that I can move files to this path.
You will not be able to detect if explorer is opened to a particular folder. There are API's to detect things like the window under the cursor and get information like the title, however, if explorer is not displaying the path in the title, it will be very hard to detect without traversing the application components and finding the address bar of the window. See WindowFromPoint and GetWindowTextA for a staring point. It should work fine under JNA and can be combined with the coordinates returned from JNativeHook.
Related
We use explorer /select command with the file path to open the file in windows explorer. https://support.microsoft.com/en-us/kb/152457 But on multiple invocations it opens a new window everytime. I am invoking the command from a java application using the process runtime APIs.
is it possible to have one window being opened ?. For e.g. if an explorer with c:/A is being opened ,repeated invocation of the same command must open the same window which is opened. ?
cheers
Saurav
It seems that your problem does not have a simple solution.
According to my understanding the "window sharing" of expplorer is not the explorer's feature. Please take a look on the following article: https://support.microsoft.com/en-us/kb/241911
(Although this article is talking about Internet Explorer I guess it is relevant for file exploerer as well).
According to my user experience the window sharing happens only when you are getting to directory via some kind of shortcut and does not happen when you are running explorer explicitly. For example if you type in "run" window "explorer" the new window is always created, however if you type "c:\" the window will be re-used.
You want to execute explorer with specific option, so you have to run it explicitly, therefore no window re-use can be achieved.
But I can suggest you 2 workarounds.
Do not use /select option. "Run" the base directory of the file you want to select. This will guarantee the window reuse. Then "select" file using java.awt.Robot by "typing" its name.
Manage the opened Explorer windows yourself into your java application. You can store map of file-to-exploerer window handler. When application wants to run open explorer for file that is already selected in other explorer window, activate it. To do this you need some JNI/JNA code. Take a look on the following discussions for details.
In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?
Find out what application (window) is in focus in Java
I realise that there are other questions on this topic, all of which I have attempted to implement the answers of and failed. I would like to end up with a full blown answer, ideally with a demonstration, on how to, in Windows and only Windows set the desktop background instantly without having the user log in and out or lock and log back in. The approach that involves using the runtime console to push the registry entries about and then rundll32 user32.dll call UpdatePerUserSystemPreferences has yet to work for me. The desired behaviour is achieved when the user right clicks an image file in explorer and selects 'Set as desktop background'. I'd like to do that programatically even if it devolves to the level of opening a hidden explorer window and right-clicking a file in it as long as the user sees nothing of it. The application in question updates the user's desktop background image with useful system information. The image to be used will be generated and regenerated every five seconds.
Can I change my Windows desktop wallpaper programmatically in Java/Groovy?
So the correct way is with JNA if you are not familiar with JNA or if you haven't used JNA the link above is for you. Otherwise you are right about using natives but you never stated how you are using them so I am just taking shots in the dark here.
I have a hard time dragging and dropping files from a remote location to windows explorer. I use a swing ui that displays the contents of the server. Now I have implemented a TransferHandler and a Transferable to bring the files to windows explorer.
The problem here is: Windows explorer, or almost any drag operation, calls the method Transferable.getTransferData over and over again, not just when the mouse button is released over the drag target. This is problematic for me because getTransferData fetches the files from the server (which takes quite some time).
IMHO I need some sort of lazy file but I am unsure how the drag handling on windows is implemented. I want to fetch the files only if the mouse button is released over a valid drop target for the files in the native system.
Does anybody know how this can be achieved?
I have an application (Java, Windows) that when opened, shows a splash screen (Good, right?). I want to know how I could change it each time the application loads (or set it to load from a location outside the app cuz I could change that). I'm using netbeans if that helps. Also, this application gets installed to their program files directory. Ideally, I would like to be able to load from %AppData%. I can't seem to figure out this part though! Thanks!
UPDATE*
Here is my folder structure and some more info!
(system flagged this is being subjective but i don't see how, anyone explain ?)
Anyway, as my title asks,can you create a 3D component using JOGL?
What I'm trying to do is, imagine an empty cylinder. You cut the cylinder in two halves and you're looking into one half.
On the inside I want to stick images...not entirely sure to what purpose this will serve yet but i'm playing around with JOGL, been through the NEHE tutorials and others and the idea came to me from an app I saw on my phone.
I'm not sure how this would work but my first thought was that its probably needs to be a subclass of JPanel or JFrame for the sake of being able to easily add normal components, but then I'm not sure...
I know I need to become more familiar with JOGL but this is my little Christmas mission but I'd appreciate any suggestions on how i could do this (eventually) or if i should just leave it as an idea and continue to play with the API.
The essence of JOGL is that you create a Java component and render GL calls to it. This needs to be an implementer of GLDrawable (typically either GLJPanel if you are working with Swing and GLCanvas if you are not). You can then draw whatever 3D scene you want into it using the JOGL calls, and it behaves like the appropriate kind of Java Component (with a few restrictions).
The other thing you can do is draw your 3D scene offscreen to a GLPbuffer and then draw the resulting bitmap to the screen as part of the component.
Well ., first of all you need to setup Eclipse and create the JOGL library:
Go to the top menu bar, click Window -> Preferences and click new and type a name for your library, such as jogl-2.0. Leave the System library (added to the boot class path) checkbox unchecked and click ok.
Back in the user libraries panel, you should see your library appear and click add JARs.. and navigate to the location where you extracted your JOGL library and then open the 'lib' directory, which contains all the various JAR files and native libraries for JOGL. Select the following JARs: gluegen-rt.jar, jogl.all.jar, nativewindow.all.jar, newt.all.jar and click ok to add these four JARs to your user library. You should see them listed under jogl-2.0 now.
Click native library location and then edit on the right and select External Folder.. and navigate to the same directory all the JAR files for JOGL are in. This should be the 'lib' directory inside the location you extracted the JOGL files, and click ok.
Now you simply have to tell your project to use your JOGL user library, right click the project folder and select Properties, select Java Build Path and click -> Libraries tab at the top -> add library -> select user library and click next, then put a check mark next to JOGL-2.0 and click finish.
I hope that you want to make something created by you and not copied :)
Now ., put the code here to see what you have and if something is wrong.