Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
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; } }
|