-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b120
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b71)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-rc-b71, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux helium 2.6.12-10-amd64-generic #1 Mon Jan 16 17:16:24 UTC 2006 x86_64 GNU/Linux
Windows XP
A DESCRIPTION OF THE PROBLEM :
All the native "tray icons" on my Ubuntu system perform their action when I single-click on them. A Java TrayIcon, though, doesn't respond until I double-click.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Single-clicking on the tray icon should say "ouch!".
ACTUAL -
I have to double-click before I see "ouch!".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class SystemTrayTest {
private TrayIcon trayIcon;
private BufferedImage image;
public static void main(String[] args) {
new SystemTrayTest();
}
public SystemTrayTest() {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Dimension size = tray.getTrayIconSize();
image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Ouch!");
}
};
trayIcon = new TrayIcon(image, "test");
trayIcon.addActionListener(listener);
try {
tray.add(trayIcon);
} catch (AWTException ex) {
ex.printStackTrace();
}
Timer timer = new Timer(50, new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateImage();
}
});
timer.start();
} else {
System.out.println("no system tray!");
}
}
int i = 0;
private void updateImage() {
Graphics2D g = image.createGraphics();
g.setColor(new Color(i, i, i));
i = (i + 1) % 256;
g.fillRect(0, 0, image.getWidth(), image.getHeight());
trayIcon.setImage(image);
trayIcon.setToolTip("Value: " + i);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If you add a MouseListener instead, you can use mouseClicked to perform an action on single click, but to avoid Java applications feeling non-native, the ActionListener behavior should be fixed.
java version "1.6.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b71)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-rc-b71, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux helium 2.6.12-10-amd64-generic #1 Mon Jan 16 17:16:24 UTC 2006 x86_64 GNU/Linux
Windows XP
A DESCRIPTION OF THE PROBLEM :
All the native "tray icons" on my Ubuntu system perform their action when I single-click on them. A Java TrayIcon, though, doesn't respond until I double-click.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Single-clicking on the tray icon should say "ouch!".
ACTUAL -
I have to double-click before I see "ouch!".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class SystemTrayTest {
private TrayIcon trayIcon;
private BufferedImage image;
public static void main(String[] args) {
new SystemTrayTest();
}
public SystemTrayTest() {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Dimension size = tray.getTrayIconSize();
image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Ouch!");
}
};
trayIcon = new TrayIcon(image, "test");
trayIcon.addActionListener(listener);
try {
tray.add(trayIcon);
} catch (AWTException ex) {
ex.printStackTrace();
}
Timer timer = new Timer(50, new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateImage();
}
});
timer.start();
} else {
System.out.println("no system tray!");
}
}
int i = 0;
private void updateImage() {
Graphics2D g = image.createGraphics();
g.setColor(new Color(i, i, i));
i = (i + 1) % 256;
g.fillRect(0, 0, image.getWidth(), image.getHeight());
trayIcon.setImage(image);
trayIcon.setToolTip("Value: " + i);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If you add a MouseListener instead, you can use mouseClicked to perform an action on single click, but to avoid Java applications feeling non-native, the ActionListener behavior should be fixed.