-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
generic, x86
-
generic, windows_nt, windows_2000
java version "1.4.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b40)
Java HotSpot(TM) Client VM (build 1.4beta-B40, mixed mode)
This bug appears to have been introduced during the focus manager enhancements at build 35. It doesnt' appear in b34. This bug appears on both Windows and Solaris but I haven't done a lot of exhaustive testing on Solaris.
Upon initialization of the following application, the focus owner appears to be null. If the button is added to the center of the content pane the the focus owner is correctly set to the button. I'm not sure what the exact circumstances is for setting the focus but in previous builds, the focus was set to one of the JMenus upon initialization.
If you use "% java Bug true" to start up the test application then the timer will report the focus owner every 2 seconds.
>>>> Bug.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class Bug extends JFrame {
private Timer timer;
private JButton timerButton;
public Bug() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add("North", createMenuBar("1 - First Menu", true));
content.add("South", createMenuBar("2 - Second Menu", false));
ActionListener timerListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
reportFocusStatus();
}
};
timer = new Timer(2000, timerListener);
timerButton = new JButton("Start");
timerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (timer.isRunning()) {
timer.stop();
timerButton.setText("Start Timer");
} else {
timer.start();
timerButton.setText("Stop Timer");
}
}
});
// content.add(timerButton, BorderLayout.CENTER);
pack();
show();
}
public void startTimer() {
timer.start();
}
public void stopTimer() {
timer.stop();
}
public JMenuBar createMenuBar(String str, boolean bFlag) {
JMenuBar menubar = new JMenuBar();
JMenuItem menuitem;
JMenu menu = new JMenu(str);
menu.setMnemonic(str.charAt(0));
menubar.add(menu);
for(int i = 0; i < 10; i ++) {
menuitem = new JMenuItem("JMenuItem" + i);
if(bFlag)
menuitem.setMnemonic('0' + i);
menu.add(menuitem);
}
return menubar;
}
// Focus diagnostic
public void reportFocusStatus() {
// KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
// Component comp = fm.getFocusOwner();
Component comp = this.getFocusOwner();
String className = "null";
if (comp != null) {
className = comp.getClass().getName();
}
System.out.println("FocusManager: getFocusOwner = " + className);
}
//
// Use "true" as the first arg to start the focus status timer.
public static void main(String argv[]) {
Bug bug = new Bug();
if (argv.length > 0 && argv[0].equals("true")) {
bug.startTimer();
}
}
}
<<<< end Bug.java
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b40)
Java HotSpot(TM) Client VM (build 1.4beta-B40, mixed mode)
This bug appears to have been introduced during the focus manager enhancements at build 35. It doesnt' appear in b34. This bug appears on both Windows and Solaris but I haven't done a lot of exhaustive testing on Solaris.
Upon initialization of the following application, the focus owner appears to be null. If the button is added to the center of the content pane the the focus owner is correctly set to the button. I'm not sure what the exact circumstances is for setting the focus but in previous builds, the focus was set to one of the JMenus upon initialization.
If you use "% java Bug true" to start up the test application then the timer will report the focus owner every 2 seconds.
>>>> Bug.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class Bug extends JFrame {
private Timer timer;
private JButton timerButton;
public Bug() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add("North", createMenuBar("1 - First Menu", true));
content.add("South", createMenuBar("2 - Second Menu", false));
ActionListener timerListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
reportFocusStatus();
}
};
timer = new Timer(2000, timerListener);
timerButton = new JButton("Start");
timerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (timer.isRunning()) {
timer.stop();
timerButton.setText("Start Timer");
} else {
timer.start();
timerButton.setText("Stop Timer");
}
}
});
// content.add(timerButton, BorderLayout.CENTER);
pack();
show();
}
public void startTimer() {
timer.start();
}
public void stopTimer() {
timer.stop();
}
public JMenuBar createMenuBar(String str, boolean bFlag) {
JMenuBar menubar = new JMenuBar();
JMenuItem menuitem;
JMenu menu = new JMenu(str);
menu.setMnemonic(str.charAt(0));
menubar.add(menu);
for(int i = 0; i < 10; i ++) {
menuitem = new JMenuItem("JMenuItem" + i);
if(bFlag)
menuitem.setMnemonic('0' + i);
menu.add(menuitem);
}
return menubar;
}
// Focus diagnostic
public void reportFocusStatus() {
// KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
// Component comp = fm.getFocusOwner();
Component comp = this.getFocusOwner();
String className = "null";
if (comp != null) {
className = comp.getClass().getName();
}
System.out.println("FocusManager: getFocusOwner = " + className);
}
//
// Use "true" as the first arg to start the focus status timer.
public static void main(String argv[]) {
Bug bug = new Bug();
if (argv.length > 0 && argv[0].equals("true")) {
bug.startTimer();
}
}
}
<<<< end Bug.java
- duplicates
-
JDK-4407753 JMenu:Keyboard navigation not working in Windows releases.
- Closed
-
JDK-4461451 Merlinb65:SwingSet2Demo:Alt+Mnemonic feature stops working on changing L&F
- Closed
-
JDK-4469090 Menu cannot be opened with mnemonic if frame has no component in content pane
- Closed
-
JDK-4484334 JMenuItem.setMnemonic() does not work properly in 1.4beta
- Closed