-
Bug
-
Resolution: Duplicate
-
P4
-
6, 7
-
generic, x86
-
generic, windows_xp
Run the testcase below,
you'll see the messageBox and the green trayicon appear
Click on the green trayIcon ->
ava.lang.ClassCastException: java.awt.TrayIcon cannot be cast to java.awt.Component
at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:810)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2376)
etc...
comes up
===Test case===
OS: Windows XP
JDK 6,7
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class bug {
public static void main(String[] args) throws Exception {
SystemTray tray = SystemTray.getSystemTray();
TrayIcon ti = new TrayIcon(getImage(), "Hello");
tray.add(ti);
final JPopupMenu popup = new JPopupMenu("Menu");
popup.add(new JMenuItem("Item"));
ti.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
popup.setLocation(e.getX(), e.getY());
popup.setVisible(true);
}
});
JOptionPane.showMessageDialog(null, "message");
}
static Image getImage() {
BufferedImage im = new BufferedImage(32, 35, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) im.getGraphics();
g2.setColor(Color.GREEN);
g2.fillRect(0, 0, im.getWidth(), im.getHeight());
g2.dispose();
return im;
}
}
you'll see the messageBox and the green trayicon appear
Click on the green trayIcon ->
ava.lang.ClassCastException: java.awt.TrayIcon cannot be cast to java.awt.Component
at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:810)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2376)
etc...
comes up
===Test case===
OS: Windows XP
JDK 6,7
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class bug {
public static void main(String[] args) throws Exception {
SystemTray tray = SystemTray.getSystemTray();
TrayIcon ti = new TrayIcon(getImage(), "Hello");
tray.add(ti);
final JPopupMenu popup = new JPopupMenu("Menu");
popup.add(new JMenuItem("Item"));
ti.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
popup.setLocation(e.getX(), e.getY());
popup.setVisible(true);
}
});
JOptionPane.showMessageDialog(null, "message");
}
static Image getImage() {
BufferedImage im = new BufferedImage(32, 35, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) im.getGraphics();
g2.setColor(Color.GREEN);
g2.fillRect(0, 0, im.getWidth(), im.getHeight());
g2.dispose();
return im;
}
}
- duplicates
-
JDK-6536033 JPopupMenu and TrayIcon ClassCastException
- Closed
-
JDK-6583251 One more ClassCastException in Swing with TrayIcon
- Closed
- relates to
-
JDK-6565779 NullPointerException thrown when dragging the tray icon and dropping it on a file dialog, XToolkit
- Closed
-
JDK-6285881 JTrayIcon: support Swing JPopupMenus for tray icons
- Closed