user1820845
user1820845

Reputation:

KeyboardFocusManager issue, Maven vs IDE build

I am trying to add keyboard shortcuts to an existing Java app. The relevant part is as follows:

    public final class Main{        

    ...
    private MyKeyEventDispatcher keyDispatcher; /*implements KeyEventDispatcher*/
    ...
    KeyboardFocusManager manager =KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyDispatcher = new MyKeyEventDispatcher(this);
    manager.addKeyEventDispatcher(keyDispatcher);
    viewer = makeJViewer(); /*an extension of JPanel, which shows a video stream.*/
    ...
    }

Now, the keyboard focus system works as one would expect with the software rendering. However, since the addition of GL rendering support, the behaviour is different. Upon starting the program, keyboard manager works fine. child objest of Main have the focus and the focus manager behaves as defined in Main. When I click on the stream-video button however, ie. when internal JPanels inside Jviewer are rendererred for the first time, although the same buttons and Panels keep the focus, the keyboard manager suddenly stop working. I will have to click on the Jviewer or the gui tools such as buttons, etc. or Tab-out and then tab-in the program for the keyboard to work again. After that, it works fine. Also, this only happens the first time a stream is loaded.

I should also say that this behaviour only occurs with my windows machine and the linux machine handles the same (maven) build just fine. What is interesting, is that if I run the same program in the IntelliJ build environment with JDK java 1.6.0.39, it also works fine in windows.

My questions are:

  1. What is causing the problem? Is the Jviewer somehow not "revalidated" after the rendering of those internal stream JPanels?
  2. Why does the same build work in Windows and not in linux? Something to do with LookAndFeel?
  3. On Windows, Why does the IntelliJ build work fine and the Maven build doesn't? They do seem to have different set of paths for looking up libraries, etc.
  4. How does the focus subsystem decide on the KeyboardFocusManager to use? Is there anything like: getCurrentKeyboardFocusManager().isItBlank() or any way of checking its content programmatically?

  5. Unfortunately the project is fairly modular and I can't define the action for the keyboard shortcuts in my "swing package" as my "Main" package imports "Swing" and Java doesn't like circular dependency; if it wasn't I could define keyboard manager for each child object, including Jviewer individually, but I can't! Is there a property to set so that all the Components in a given window would use the same KeyboardFocusManager?

FYI, Maven version: 3.2.5 and uses same Java JDK as my IDE.

Upvotes: 0

Views: 90

Answers (1)

user1820845
user1820845

Reputation:

The focus manager issue can be resolved by clearing the global focus owner: KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();

Upvotes: 0

Related Questions