-
Bug
-
Resolution: Fixed
-
P1
-
1.4.0
-
rc1
-
generic, x86, sparc
-
generic, linux, windows_2000
-
Verified
Name: asR10013 Date: 09/06/2001
JDK : JDK1.4.0-beta-b78
JCK : JCK1.4-b09, JCK1.3a
Platform[s] : RedHat Linux 7.1, Windows 2000
switch/Mode : -client -Xmixed -Xfuture
JCK test owner : http://javaweb.eng/jck/usr/owners.jto
Failing Test : api/javax_swing/interactive/JButtonTests.html#JButton [JButtonTest0010]
The test verifies behavior of JButton.setMnemonic( int ) method.
However when mnemonic keys are pressed first time the corresponding button remains pressed after
releasing mnemonic keys combination.
It seems as focus issue: if focus is set to any control before first press of mnemonic keys (e.g. via mouse click) the test
behaves correctly.
Test source location:
=====================
/net/jdk/export/disk8/local.java/jck1.4/JCK-runtime-14/tests/api/javax_swing/interactive/JButtonTests.java
jtr file location:
==================
/net/jtgb4u4c.eng/export/sail15/results/merlin/b77/jck14/linux/redhat7.1_smp_gnome_plugin_ns6.1_linux-24/workDir/api-interactive/javax_swing/interactive/JButtonTests_JButton.jtr
How to reproduce:
====================
1. Run the following script (probably, you need to change JCK and JAVA_HOME paths)
2. Press Alt+1 then release it.
You will see that button 1 remains pressed.
--------Script START---------------------
#!/bin/sh
JAVA_HOME=/net/jdk/export/disk8/local.java/jdk1.4/linux-i386
JCK=/net/jdk/export/disk8/local.java/jck1.4/JCK-runtime-14
export CLASSPATH="$JCK/classes:$JCK/javatest.jar"
executeClass="javasoft.sqe.tests.api.javax.swing.interactive.JButton.JButtonTests -TestCaseID JButtonTest0010 -TestDirURL file:///$JCK/tests/api/javax_swing/interactive/JButtonTests.html#JButton"
$JAVA_HOME/bin/java -Xfuture ${executeClass}
---------Script END----------------------
Test output:
=============
JButtonTest0010: Failed. setMnemonic(int i) method does not work as expected.
STATUS:Failed.tests: 1; failed: 1; first test case failure: JButtonTest0010
Specific Machine Info:
=====================
Hostname: linux-24
OS: RedHat Linux 7.1
Hostname: Linux-22
OS: Windows 2000 Professional
======================================================================
Here is a more concise test case showing the bad behavior:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
* This program demonstrates a problem with Mnemonics if
* a heavywight component has focus when a lightweight
* mnemonic is selected. What happens is that the key-pressed
* event is not passed to the lightweight component and only
* the key-released event is. This confuses the button into
* thinking that it is still selected. The solution is to
* provide focus to a swing component if swing and awt
* components are mixed.
*/
public class Mnem extends JFrame {
public Mnem (boolean beingGood) {
super();
getContentPane().setLayout(new FlowLayout());
Button awtButton = new Button("AWT Button");
JButton swingButton = new JButton("Hold Meta-key/ALT+1");
swingButton.setMnemonic(KeyEvent.VK_1);
JLabel label = new JLabel((beingGood?"GOOD BEHAVIOR":"BAD BEHAVIOR"));
getContentPane().add(label);
getContentPane().add(awtButton);
getContentPane().add(swingButton);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Dimension ScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension thisSize = getSize();
int x = ScreenSize.width / 2 - thisSize.width / 2;
if (x < 0)
x = 0;
int y = ScreenSize.height / 2 - thisSize.height / 2;
if (y < 0)
y = 0;
setLocation(x, y);
pack();
if (beingGood) {
swingButton.requestFocus();
} else {
awtButton.requestFocus();
}
setVisible(true);
}
public static void main(String[] args) {
if (args.length > 0) {
new Mnem( true );
} else {
new Mnem( false );
}
}
}
###@###.### 2001-09-13
============================================================================
1) The following 2 subtests fails on sparc and on b79 with JCK14-b09 .
api/javax_swing/interactive/JButtonTests.html#JButton [JButtonTest0008, JButtonTest0010]
Test Output:
=============
JButtonTest0008: Failed. setText(String s) method does not work as expected.
JButtonTest0010: Failed. setMnemonic(int i) method does not work as expected.
result: Failed. tests: 12; passed: 10; failed: 2; first test case failure: JButtonTest0008
2) Another test also fails on b79
api/javax_swing/interactive/JToggleButtonTests.html#JToggleButton [JToggleButtonTest0007]
Test Output:
=============
JToggleButtonTest0007: Failed. setText() method does not work as expected.
result: Failed. tests: 9; passed: 8; failed: 1; first test case failure: JToggleButtonTest0007
###@###.### 2001-09-18
- duplicates
-
JDK-4504097 lightweight button mnemonic not invoked correctly if focus on heavyweight
-
- Closed
-
- relates to
-
JDK-4706883 REGRESSION: ActionMap misses VK_PRINTSCREEN
-
- Resolved
-