写了一下...仅供参考...
[CODE]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Demo extends JFrame{
private JList jlTest;
public Demo(){
super("显示PopupMenu");
jlTest = new JList(); //实例化一个JList
final JPopupMenu jmPopupMenu = new JPopupMenu(); //创建一个JPopupMenu
JMenuItem jmiMenuItem = null;
for(int i=0;i<5;i++){ //添加JMenuItem
jmiMenuItem = new JMenuItem("第"+i+"项");
jmPopupMenu.add(jmiMenuItem);
}
jlTest.addMouseListener(new MouseAdapter(){ //注册鼠标监听者.右击时.弹出PopupMenu
public void mousePressed(MouseEvent e){
if(e.getButton()==e.BUTTON3){
jmPopupMenu.show(jlTest,e.getX(),e.getY());
}
}
});
this.getContentPane().add(jlTest,BorderLayout.CENTER);
this.setSize(640,480);
this.setVisible(true);
}
public static void main(String[] args){
new Demo();
}
}
[/CODE]