JWindow弹出式菜单问题
给JWindow添加弹出式菜单,弹不出来。把JWindow换成JFrame就可以弹出来了。因为我的程序必须使用JWindow,所以希望大家帮帮忙,让JWindow可以弹出...
给JWindow添加弹出式菜单,弹不出来。把JWindow换成JFrame就可以弹出来了。因为我的程序必须使用JWindow,所以希望大家帮帮忙,让JWindow可以弹出弹出式菜单,或是说明弹不出来的原因。
匿名的朋友,我用的是JDK6.0。
奇怪的是,当我把程序打包为jar文件后,双击运行时就可以弹出来了。呵呵~,看来对JDK6.0还是不太了解。现在正在看源码,不过没有发现什么问题。也许是Popup类的问题。讲究中!~
JDK1.6_02的问题,更换为JDK1.6_10之后,总是解决了。 展开
匿名的朋友,我用的是JDK6.0。
奇怪的是,当我把程序打包为jar文件后,双击运行时就可以弹出来了。呵呵~,看来对JDK6.0还是不太了解。现在正在看源码,不过没有发现什么问题。也许是Popup类的问题。讲究中!~
JDK1.6_02的问题,更换为JDK1.6_10之后,总是解决了。 展开
2个回答
2009-06-12
展开全部
//: JWin.java 能正常响应:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.JWindow;
public class JWin {
public static void main(String[] args) {
JWindow w = new JWindow();
w.setAlwaysOnTop(true);
w.setLayout(new FlowLayout(FlowLayout.LEFT));
final JPopupMenu pm = new JPopupMenu();
pm.add(" a ");
pm.add(" b ");
pm.add(" c ");
JButton b = new JButton("exit");
w.add(b);
JLabel l = new JLabel("<html><br/>弹出式菜单<br/><br/>");
l.setOpaque(true);
l.setBackground(Color.red);
w.add(l);
// w.getContentPane().addMouseListener(new MouseListener(){
// public void mouseClicked(MouseEvent e) {}
// public void mouseEntered(MouseEvent e) {}
// public void mouseExited(MouseEvent e) {}
// public void mousePressed(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
// public void mouseReleased(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
// void pop(MouseEvent e){
// pm.show((JComponent)e.getSource(),e.getX(),e.getY());
// }
// });
l.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
public void mouseReleased(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
void pop(MouseEvent e){
pm.show((JComponent)e.getSource(),e.getX(),e.getY());
}
});
b.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {System.exit(0);}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
w.setSize(200,100);
w.setVisible(true);
}
}
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.JWindow;
public class JWin {
public static void main(String[] args) {
JWindow w = new JWindow();
w.setAlwaysOnTop(true);
w.setLayout(new FlowLayout(FlowLayout.LEFT));
final JPopupMenu pm = new JPopupMenu();
pm.add(" a ");
pm.add(" b ");
pm.add(" c ");
JButton b = new JButton("exit");
w.add(b);
JLabel l = new JLabel("<html><br/>弹出式菜单<br/><br/>");
l.setOpaque(true);
l.setBackground(Color.red);
w.add(l);
// w.getContentPane().addMouseListener(new MouseListener(){
// public void mouseClicked(MouseEvent e) {}
// public void mouseEntered(MouseEvent e) {}
// public void mouseExited(MouseEvent e) {}
// public void mousePressed(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
// public void mouseReleased(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
// void pop(MouseEvent e){
// pm.show((JComponent)e.getSource(),e.getX(),e.getY());
// }
// });
l.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
public void mouseReleased(MouseEvent e) {if(e.isPopupTrigger())pop(e);}
void pop(MouseEvent e){
pm.show((JComponent)e.getSource(),e.getX(),e.getY());
}
});
b.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {System.exit(0);}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
w.setSize(200,100);
w.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询