AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Incorrect and permanent loss of keyboard focus

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
James L. Terman
Guest





PostPosted: Fri May 04, 2007 2:55 am    Post subject: Incorrect and permanent loss of keyboard focus Reply with quote



I have a small sample problem that replicates my problem. The program
creates a window with a text field that has keyboard focus.

The window has a menu item that I use to create another window of that
type that correctly gets the keyboard focus.

I then click on the old window, bring it to front. It does not get the
keyboard focus like it should in Linux. It will work correctly in windows.

I tried adding the call requestFocusInWindow which did not help and led
to unpredictable behavior. The problem seems to be that I am in the
situation where the call

KeyboardFocusManager.getCurrentKeyboardFocusManager
().getPermanentFocusOwner()

is returning the expected Component. The problem is that the KeyListener
class that is registered with the Component is not being called when a
key is being pressed.

The issue is that I have a component that has the keyboard focus, but the
KeyListener class
is not responding.

This seems to be a linux only problem which makes it only more mysterious.

Quote:
uname -a
Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686

i686 i386 GNU/Linux
Quote:
java -version
java version "1.5.0_11"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
Quote:
javac -version
javac 1.5.0_11


import java.awt.event.*;
import javax.swing.*;

class SwingWindow extends JFrame {

SwingWindow() {
super("SwingWindow");
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem newItem = new JMenuItem("New");
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
SwingWindow.createAndShowGUI();
}
});
fileMenu.add(newItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JTextField text = new JTextField(200);
getContentPane().add(text);
pack();
setSize(700, 275);
}

public static void createAndShowGUI() {
JFrame frame = new SwingWindow();
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Back to top
Knute Johnson
Guest





PostPosted: Fri May 04, 2007 10:10 pm    Post subject: Re: Incorrect and permanent loss of keyboard focus Reply with quote



James L. Terman wrote:
Quote:
I have a small sample problem that replicates my problem. The program
creates a window with a text field that has keyboard focus.

The window has a menu item that I use to create another window of that
type that correctly gets the keyboard focus.

I then click on the old window, bring it to front. It does not get the
keyboard focus like it should in Linux. It will work correctly in windows.

I tried adding the call requestFocusInWindow which did not help and led
to unpredictable behavior. The problem seems to be that I am in the
situation where the call

KeyboardFocusManager.getCurrentKeyboardFocusManager
().getPermanentFocusOwner()

is returning the expected Component. The problem is that the KeyListener
class that is registered with the Component is not being called when a
key is being pressed.

The issue is that I have a component that has the keyboard focus, but the
KeyListener class
is not responding.

This seems to be a linux only problem which makes it only more mysterious.

uname -a
Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686
i686 i386 GNU/Linux
java -version
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
javac -version
javac 1.5.0_11

import java.awt.event.*;
import javax.swing.*;

class SwingWindow extends JFrame {

SwingWindow() {
super("SwingWindow");
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem newItem = new JMenuItem("New");
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
SwingWindow.createAndShowGUI();
}
});
fileMenu.add(newItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JTextField text = new JTextField(200);
getContentPane().add(text);
pack();
setSize(700, 275);
}

public static void createAndShowGUI() {
JFrame frame = new SwingWindow();
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

I tried your program and I'm not seeing the problem you describe
although I have seen it with one of my own programs. You can see mine at:

http://www.knutejohnson.com/chat.html

Press the 'Connect' button and a JOptionPane input dialog is opened.
When closed the focus never returns to the JTextField where it belongs
even with a call to requestFocus(). It does however return if you
minimize the browser window and then maximise it. Just for my
curiosity, try minimizing your program window and then maximize it to
see if the focus goes where it belongs.

I'm not sure why your program doesn't fail for me but I was not able to
make a test program that failed at all. I thought it might be Applet
related but apparently it isn't.

There is something fishy in Linux I think.

--

Knute Johnson
email s/nospam/knute/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.