当前位置: 技术问答>java相关
如何编写在LIST中,用鼠标右键弹出菜单的程序?谢谢!
来源: 互联网 发布时间:2015-06-17
本文导语: rt | 自己刚写的,很难看,但是你的要求可以达到,你自己再改改。 package csdn; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; import java.awt.event.*; public class Frame2 extends JFra...
rt
|
自己刚写的,很难看,但是你的要求可以达到,你自己再改改。
package csdn;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.awt.event.*;
public class Frame2 extends JFrame {
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JList jList1 = new JList();
TitledBorder titledBorder1;
JPopupMenu jPopupMenu1 = new JPopupMenu();
JMenuItem jMenuItem0 = new JMenuItem("menuitem0");
public Frame2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Frame2 frame21 = new Frame2();
frame21.setBounds (120,120,300,300);
frame21.show ();
}
private void jbInit() throws Exception {
titledBorder1 = new TitledBorder("");
jPanel1.setLayout(borderLayout1);
jList1.setBorder(BorderFactory.createLineBorder(Color.black));
jList1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jList1_mouseClicked(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
Vector listData=new Vector();
for ( int i=0;i