(Java 7) Swing application loses keyboard focus - java

My application is a GUI frontend for a database, and is built using Java's Swing library. The application is compiled using Java 5 (1.5).
When the application is ran using Java 7 I am able to write in textfields, comboboxes, etc. using the keyboard, until the data is loaded from the database then the cursor continues to blink but what I type is not typed on the screen. However, if I click on another windows e.g. my browser and then come back to my application, or minimize and maximize my application, the keyboard input works and behaves as normal.
When I run with Java 1.5 or 1.6, however this issue does not appear.Any insight on what might have changed in Java 1.7, and possibly a workaround?
PS: So far I made a workaround as follows:
frame.setFocusableWindowState(false);
frame.setFocusableWindowState(true);
However, I have this inside a timer, as I don't know where exactly the issue occurs. This is not really a proper solution...
Thanks

Related

Mouse focus in java applet with some java versions

We have written an application to run oracle forms java applets years ago.
The application works fine on forms versions 11.1.1.7.
But now we have on some sites a forms 11.1.2.x installed.
If we run the application with IE, firefox or chrome we don't have any mouse focus problems and everything runs fine. Also if we use java web start.
But if we run the application with our own written application we have mouse focus problems with jre 7 and 8. If we run the same application with jre 6 we don't have any problems at all.
I can't post all the code because it is too much code.
Can someone explain how it is possible that if we run the applet with a browser or java webstart it works fine with jre 8 and if we run it with our application with jre 8 it has mouse focus problems. And if we run it with jre 6 we don't have the problems?
Update
We just found out that a go_item in the first form we start is causing this error. If we click on another item in the first form before continuing we don't lose the focus.
We have tried putting a synchronize after the go_item but this doesn't seem to resolve the issue.

java applet using Next-generation plug-in

I have a web application (struts 1.3, Weblogic 10.3.0, Toplink, Oracle) that has a Java applet which isn’t working in the browser (IE7/8) when the Next-Generation Plug-in setting is enabled in the Java control panel but works fine when it’s disabled. The trouble is that this setting is set to disappear in an upcoming Java release meaning that my users would have to keep using Java 1.6_xx on their workstations as they are currently. I have little influence over which version they use because they are all governed by their local IT departments across the country. So, either I have to find a simple fix to allow the Next-Generation setting to work, or we have to look at replacing/rewriting the applet with something else (but would be a last resort due to funding constraints), most likely something AJAX-friendly so as to avoid the need for a plugin. This application is quite old, written around 2001 before AJAX was really around.
The main window has a left, right, and top frame (JSP’s), as well as a center frame which is where the applet is. The applet has a main content area in the middle and a lower panel at the bottom which has some buttons. The buttons tell the content area (which is basically a treegrid) what to do (Save, Copy, change status, etc ). When I press one of the buttons the entire window (surrounding frames plus the applet itself) repeat inside the area where the applet is. It’s like a kaleidoscope or like a repeating fractal pattern kind of thing, or like when you take a picture of yourself in the mirror and you see the room repeated over and over in the mirror. In this case it repeats for each button press and the repeated set gets smaller each time. Weird!!
So, based on my research, the Java Next-Generation plugin works differently by allowing more than one process or thread whereas the classic plugin only uses a single thread. So my suspicion is that a new process is being spawned for each button press. I tried using the “separate_jvm” applet parameter but it made no difference whether it was set to true or false. I don’t see any other applet parameters which seem to be relevant.
Another idea I had is that maybe it’s something to do with the JSP frameset, maybe something like “target=_top” needs to be added somewhere…but I’m not sure how this relates to applet threads if at all.
Anyone have any suggestions, ideas or experiences that might help?
you can use velocity to handle these type of problem and it will also help you for future enhancement also.
The problem is not related to version of IE but rather to version of Java. Below excerpt from letter of certificate provider (they took it from some forum, so direct link to source cannot be provided):
For JDK version higher than 1.6.0 and below 1.6_15, you can just
clear all kinds of cache in web browser, java console and java control
panel. Then it should works fine!
For JDK version between 1.6_15 and 1.6_30, you should disable the "next-generation java" option in java control panel.
For JDK version higher than 1.6_30, you should turn on "next-generation java" option in java control panel.

Java Robot get focus of other application

I have a java Robot program ,where it can type a word on notepad,word etc,.
But the problem is i am not getting focus of window application, when i tried to enter the cursor in its textbox manually by using ALT-TAB,
And the application is not available in the list ,while doing ALT-TAB ,
also it is not visible in Task Manager-> Application tab
but, it is available with Processes tab of Task Manager.
Is there any solution to get focus of that windows application for keyPress using Java Robot.
Also ,in some other PC's ,i am getting Clear Focus of the application when i put the cursor manually after running the java robot program. I have installed JDK1.6 in all my PC's. It is not working only in my PC's.
Thanks in advance!!
I think that your best bet is to use JNA to allow you to make system calls.
Assuming a Windows program, you could use JNA to make calls to the user32.dll including dll functions such as FindWindowEx(...) and SetForegroundWindow(...) to set the window of your choice to the foreground.
Instead of getting the focus of the other app, you could put your robot to the background, returning whatever was in the foreground previously (ie your target app) to get the focus.

How do I run an external program inside a Java frame in netbeans in a platform independent manner?

I am currently working on a research project for a University in which I am doing GUI interactions with my database and launching an external program based on the data. I'm using runtime commands (once the OS is detected) to launch that external program with the selected data.
My question is how can I embed an external program's GUI inside a Java frame, if that is even remotely possible?
Given the clarifying comments on the question, the short answer is "no, you can't do that".
Java cannot display a native program's GUI within a JFrame, even if the target program was actually architected to allow it's GUI to be presented within another program's frame.
Are you using a console application? You have to intercept its stdout to do it correctly. So you can show the text that the 3rd party application is outputting in an UI control that you can put into JFrame.
It depends from the application you want to embed to the JFrame, but you can try to use jawt:
https://docs.oracle.com/javase/9/docs/specs/AWT_Native_Interface.html
You will be able to get the native OS specific window handle and can draw on top of it, or can you use it as a container. Note that only HW components are supported, so you will need to add Panel/Canvas to the JFrame and then use that for your native app.
This is similar to this question:
Native JNI/JAWT Swing application runs successfully on Java 6, but fails on Java 7 (64-bit Windows 7 OS)
Use java.lang.Process or java.lang.Runtime.exec.
http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html

Substance L&F seems to break when deployed as webstart in java

I think I am having a weird problem:
I 've written a small application in java implementing a JTable to display some results.
I am also using the Substance L&F as my "skin".
Everything seems to be working perfectly.
When I upload the app on my server as webstart, strange things start to happen:
At some point my app generates a little JTable. Every time I mouse over that table,
the app's JButtons or menus or any swing control in general will stop responding. My only option is to close the window and restart the application. Note that the interface seems not to be frozen but like it's lost its focus... if I try to click in any of the table's cells, the UI will still be responsive (not on the swing controls though).
If I get rid of Substance, the problem goes off and everything is working normally again.
If I use another "skin" like JTattoo everything works flawlessly as well.
This only happens when I use the webstart. Does anybody know why..?
or better has any hints on how to fix it?

Categories

Resources