I've been running up against a problem with Java Swing + my Wacom Graphire tablet for a few years in several Java applications and have now encountered it in my own.
I use a pen tablet to get around wrist issues while clicking a mouse, and it works fine under Windows except when I'm using Java applications. In Java applications, the single-click of the pen doesn't work correctly. (Usually the problem only occurs with file-selection dialog boxes or tree controls.) The pen tablet also comes with a wireless mouse that works with the same tablet, and its single-click does work correctly.
I don't know whether the problem is in the WACOM driver or in the Java Swing runtime for Windows or both. Has anyone encountered this before? I'd like to file a bug report with WACOM but I have no idea what to tell them.
I have been able to reproduce this in my own application that has a JEditorPane with an HTML document that I've added a HyperlinkListener to. I get HyperlinkEvent.ACTIVATED events on every single click with the mouse, but I do NOT get HyperlinkEvent.ACTIVATED events on every single click with the pen.
One big difference between a pen and a mouse is that when you click a button on a mouse, it's really easy to cause the button-click without mouse movement. On the pen tablet it is very hard to do this, and that seems to correlate with the lack of HyperlinkEvent.ACTIVATED events -- if I am very careful not to move the pen position when I tap the tablet, I think I can get ACTIVATED events.
Any suggestions for things to try so I can give WACOM some good information on this bug? It's really frustrating to not be able to use my pen with Java apps, especially since the pen works fine with "regular" Windows (non-Java) applications.
Normally I wouldn't ask this question here but I'd like to find out from a programmer's standpoint what might be going on so I can file a good bug report.
What you should do is add a mouseListener and see when it registers a mouseClicked(), mousePressed(), mouseReleased() event. I'm not sure if the swing reads the tablet pen as a mouse though. However, it should give you some insight into what's actually going on.
I tried dr.manhattan's suggestion and it works like a charm. I get mousePressed/mouseReleased events correctly; mouseClicked events happen always with the pen tablet mouse, but mouseClicked events do not happen with the pen unless I manage to keep the pen very still. Even a 1-pixel movement is enough to make it fail. I guess I should blame Java for this one: there's no way to specify a "click radius" for acceptible movement.
package com.example.bugs;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class WacomMouseClickBug {
public static void main(String[] args) {
JFrame jframe = new JFrame();
jframe.addMouseListener(new MouseListener(){
#Override public void mouseClicked(MouseEvent event) {
System.out.println("mouseClicked: "+event);
}
#Override public void mouseEntered(MouseEvent event) {}
#Override public void mouseExited(MouseEvent event) {}
#Override public void mousePressed(MouseEvent event) {
System.out.println("mousePressed: "+event);
}
#Override public void mouseReleased(MouseEvent event) {
System.out.println("mouseReleased: "+event);
}
});
jframe.setPreferredSize(new Dimension(400,400));
jframe.pack();
jframe.setLocationRelativeTo(null);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
}
}
I think you already got the answer yourself: Moving the pen results in some other event than a simple click, perhaps maybe a Drag and drop like event.
I'm not sure whether it's a Java/Swing or a Wacom problem, it could be that the tablet doesn't register the clicks as such but as drag events, or it could be that swing interprets the events incorrectly.
I reported this bug many years ago to Sun. It still is not fixed. Any decent ui framework will allow some movement between a press and release to generate a click event. A maximum movement of 1 pixel on a high dpi display is just ridiculous. It is not only an issue with wacom tablets, ie older people also have difficulties to keep the mouse still when clicking.
Related
i was wondering if it is possible to pass an MouseEvent, which occurs on a specific Stage to pass through the window of another program/application which to be fired there.
To be more specific, i want to program a HUD-like program for informational purposes, which should not interfere with the normal desktop usage (such as operating scrollbars/buttons which are underneath the "HUD").
One approach to accomplish such behaviour could be achieved using the Robot class in combination with an MouseListener.
Example:
scene.setOnMouseClicked(new EventHandler<MouseEvent>(){
#Override
public void handle(MouseEvent event) {
stage.hide();
robot.mousePress(InputEvent.BUTTON1_MASK)
stage.show();
}
});
That should work (not yet tried), but feels kinda like a workaround, also this attempt should make problems if one tries to handle drag & drop. Are there any other possibilities to pass any kind of MouseEvents to other windows? Is it possible to make a Stage mouse transparent such as it is possible for Nodes ?
This probably sounds simple and stupid, but for the life of me I cannot find a way to have a mouse listener which does mousePressed without having to be on a component. void mousePressed(){} doesn't seem to work the way I want it to.
Essentially I am making a java program which aims to work without graphics, and does things in the background. So if you click in chrome for example it still will effect the program.
What I was trying was this, which I realize is horribly incorrect.
class MKeyListener extends KeyAdapter {
#Override
public void keyPressed(KeyEvent e) {
moveMouse.playing = false;
}
}
As reccomended I tried the JNativeHook library, however it doesn't seem to work the way I think it should:
public class mousepresstest implements NativeMouseInputListener{
#Override
public void nativeMouseClicked(NativeMouseEvent e) {
System.out.println("worked");
}
}
It doesn't print the text on mouse pressed, am I missing something here?
Java Mouse listeners are only meant for swing/awt components and that too from the same running process.
If you want to listen for mouse/keyboard events from other apps use the JNativeHook
library.You can install a global keyboard hook and listen for keypress or a mousehook for mouse events.You do not need to use Swing or other GUI classes.
Internally JNativeHook uses JNI to provide these functionality.
Hi I have only one JDialog box in my Java application.I want to make it invisible if it lost the focus.
I've tried different method, But didn't able to trigger any of the window focus events. Here is my code:
public void windowGainedFocus(WindowEvent e) {
System.out.println("gained focus");
}
public void windowLostFocus(WindowEvent e) {
System.out.println("lost focus");
}
Responding to Focus events can be really tricky. My experience has been that pretty much any time someone has attempted to do non-standard things with focus, they come to regret it eventually. Not least among the issues is that it's not really all that portable - a lot of X-Windows based displays use focus-follows-mouse, which can result in the focus being transferred away when you're not expecting it to, resulting in early dismissal of your dialog.
That said, Sun's official tutorial is here: http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html . If I remember right, you can attach a PropertyChangeListener to the KeyboardFocusManager, and that will be triggered for focus changes: http://java.sun.com/javase/6/docs/api/java/awt/KeyboardFocusManager.html#addPropertyChangeListener%28java.beans.PropertyChangeListener%29
Use a WindowListener and handle the windowDeactivated event.
I'm searching for a solution in order to keep a JFrame always on top and with always I really mean always.
setAlwaysOnTop( true );
This won't work when I'm starting a game in fullscreen mode. I know you normally don't want your windows to stay on top but in this case it's required.
This can't be done.
For example, the Windows Task Manager, even when set to Always on Top will get covered up by full-screen applications.
This is due to the fact that full-screen applications typically use a different graphics context and can't be overlayed.
Start another process to check if the window is on top,if not, set it on top.
This is a sample code that should be helpful
public class AllWaysOnTop extends JFrame implements WindowListener {
AllWaysOnTop() {
// Code to setup your frame
addWindowListener(this);
// Code to show your frame
}
// The window event handlers. We use WindowDeactivated to
// try and keep the splash screen on top. Usually only keeps
// the splash screen on top of our own java windows.
public void windowOpened(WindowEvent event){};
public void windowActivated(WindowEvent event){};
public void windowDeactivated(WindowEvent event){
toFront();
}
public void windowIconified(WindowEvent event){};
public void windowDeiconified(WindowEvent event){};
public void windowClosed(WindowEvent event){};
public void windowClosing(WindowEvent event) {};
}
Reference
This forum post
This sounds like the kind of question that Raymond Chen always has to answer over at Link. How can you really really forever and for true keep a window in the foreground? You can't. Because what happens if somebody ELSE's window uses the same trick to keep itself always always and forever in the foreground? Which one wins?
If you mean fullscreen as in DirectX/OpenGL/whatever, I'm not sure you can (or should) really pull it off. Most operating systems disable their native windowing during full screen to improve rendering performance. Swing works via the native windowing toolkit.
You could write something that uses a timer and in short intervals (e.g., 200ms) instructs your window to go to the top. Depending on your operating system this would be exactly what you need, or a horrible cause of performance trouble or flickering.
I'm not sure but i would bet that the Fullscreen window also has Always On Top set to true, and in that case you have stumbled into the realm of undefined behavior. In general when two windows are set to always on top there is no guarantee about ordering. I think in general though the order is just dependent on the order in which they were set to always on top. So in that case i would just wait until the app has gone fullscreen to set it to always on top and see if that works.
In other cases ive seen people start threads and then occasionally reset the fram to always on top.
All these solutions are ugly, so just use the one that lets you sleep at night.
I know this post is old, but I encountered this problem and I found a satisfying solution.
My program has some notifications that I wish to be always on top, but when a movie entered full-screen, they disappeared. Fortunate, my program updates these notifications every 5 seconds, and if I call setVisible(true) on these JWindows, at each update, they regain the top position, if they have lost it.
I was looking to do the same thing as OP, have my app running in the foreground while my game ran. It doesn't work in fullscreen but if you put the game into windowed mode and adjust the window settings to fit your tv it works. I only needed the frame.setAlwaysOnTop to make it work.
i'm having the same issue as the person here, in that i need to track a frame location while it is being dragged on OS X. The question had not been resolved there, so:
how do i tell a frame that a mouse down event happened on its (OS-native) title bar or, more generally, that a mouse down event happened somewhere on the screen?
Since java 1.5
import java.awt.MouseInfo;
public class Mouse {
public static void main(String[] args) {
while ( true ) {
System.out.println( MouseInfo.getPointerInfo().getLocation() );
}
}
}
EDIT:
Native keyboard mouse hook
http://www.jotschi.de/?p=90
Using pure Java, you can never tell that a mouse down event happened on its (OS-native) title bar, or for that case any event outside you application window(excluding title bars).
It's important understand that as a programmer in AWT/Swing your context and realm and power lies only within the application window.
Best shot is to use JNI.