import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
 
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.MouseInputListener;
import javax.swing.table.DefaultTableModel;
 
//学生评教
 
public class Judge {
 
    static JPanel jj;
 
    public JPanel judge_panel(){
        jj = new JPanel();
        jj.setBounds(0, 0, 1000, 650);
        jj.setBackground(Color.blue);
        jj.setLayout(null);
        pop();
        return jj;
    }
 
    public void pop(){
        String[] tableTitleArray = {"ID","Name","Sex"};
       Object[][] body = new Object[6][tableTitleArray.length];
       for(int i = 0; i < 6;i++){
           body[i][0] = i;
           body[i][1] = "张三"+i;
           body[i][2] = "男";
       }
       final JTable table = new JTable(new DefaultTableModel(body,tableTitleArray));
       final MouseInputListener mouseInputListener = getMouseInputListener(table);//添加鼠标右键选择行
       table.addMouseListener(mouseInputListener);
       table.addMouseMotionListener(mouseInputListener);
       JScrollPane scrollPane = new JScrollPane(); 
       scrollPane.setViewportView(table);
       scrollPane.setSize(1000, 500);
       jj.add(scrollPane, BorderLayout.CENTER);
 
    }
 
    private MouseInputListener getMouseInputListener(final JTable jTable) {  
        return new MouseInputListener() {  
            public void mouseClicked(MouseEvent e) {  
                processEvent(e);  
            }  
 
            /*** 
             * //in order to trigger Left-click the event 
             */  
            public void mousePressed(MouseEvent e) {  
                processEvent(e);// is necessary!!!  
            }  
 
            public void mouseReleased(MouseEvent e) {  
                // processEvent(e);  
//                System.out.println(); 
                System.out.println(jTable.getValueAt(jTable.getSelectedRow(),jTable.getSelectedColumn()));
 
                if (e.getButton() == MouseEvent.BUTTON3) {// right click  
 
                    JPopupMenu popupmenu = new JPopupMenu();  
                    JMenuItem runM = new JMenuItem("111");  
                    JMenuItem copyParameterM = new JMenuItem("222");  
                    JMenuItem copyResponseM = new JMenuItem("333");  
//                  JMenuItem encodingM = new JMenuItem(ACTION_COMMAND_ENCODING);  
                    // JMenuItem editM=new JMenuItem("edit");  
                    MyMenuActionListener yMenuActionListener = new MyMenuActionListener();  
                    runM.addActionListener(yMenuActionListener);  
                    copyParameterM.addActionListener(yMenuActionListener);  
                    copyResponseM.addActionListener(yMenuActionListener);  
//                  encodingM.addActionListener(yMenuActionListener);  
                    popupmenu.add(runM);  
                    popupmenu.add(copyParameterM);  
                    popupmenu.add(copyResponseM);  
//                  popupmenu.add(encodingM);  
                    popupmenu.show(e.getComponent(), e.getX(), e.getY());  
                }  
            }  
 
            public void mouseEntered(MouseEvent e) {  
                processEvent(e);  
            }  
 
            public void mouseExited(MouseEvent e) {  
                processEvent(e);  
            }  
 
            public void mouseDragged(MouseEvent e) {  
                processEvent(e);  
            }  
 
            public void mouseMoved(MouseEvent e) {  
                processEvent(e);  
            }  
 
            private void processEvent(MouseEvent e) {  
                // Right-click on  
//                if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {  
//                    // System.out.println(e.getModifiers());  
////                     System.out.println("Right-click on");  
//                    
//                    int modifiers = e.getModifiers();  
//                    modifiers -= MouseEvent.BUTTON3_MASK;  
//                    modifiers |= MouseEvent.BUTTON1_MASK;  
//                    MouseEvent ne = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(),   e.getClickCount(), false);  
//                    jTable.dispatchEvent(ne);// in order to trigger Left-click  
//                    
//                    // the event  
//                }  
            }  
        };  
    }  
    class MyMenuActionListener implements ActionListener {
 
        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
 
        }  }
 
 
 
}

table 添加右键,并获取选中行信息的更多相关文章

  1. jQuery DataTables 获取选中行数据

    如题 想获取操作 DataTables 获取选中行数据 案1.主要是利用 js  getElementsByTagName 函数 然后对获取到的tr 进行操作  如下 function getChec ...

  2. jqgrid 获取选中行主键集合

    如何获取选中行的主键集合呢? 使用  getGridParam(selarrrow) 方法可获取所有选中行的主键集合. 注意:此处的主键集合是指-设置为主键的列(key: true).再次提醒:一个j ...

  3. gridview获取选中行索引及当前行数据

    gridview获取选中行索引及当前行数据 一.非直接绑定数据: <!--前台传值--> <asp:TemplateField HeaderText="操作"&g ...

  4. EasyUi DataGrid 获取选中行的checkbox

    EasyUi DataGrid 获取选中行的checkbox var checked = $(":checkbox[name=ID]:checked"); console.log( ...

  5. datagrid如何获取选中行的索引

    //datagrid获取选中行 var row =baseSelectgrid.datagrid('getSelected'); // 获取被选中行的索引 index var index=baseSe ...

  6. DHtmlx组件获取选中行的某一列对应的值

    最近刚刚接触DHtmlx这个js组件,对它还不是太了解,还在学习中,算是记录自己学习该组件的历程吧. 首先xml文件里有一个grid,有对应的checkbox,通过 var selectedId = ...

  7. bootstrapTable:获取选中行的数据

    必须要有checkbox:true和singleSelect:true,然后就可以通过var row=$("#mytab").bootstrapTable('getSelectio ...

  8. easy ui datagrid 获取选中行的数据

    取得选中行数据: var row = $('#tt').datagrid('getSelected'); if (row){ alert('Item ID:'+row.itemid+" Pr ...

  9. 如何用jQuery获取选中行固定列的数据

    [本文出自天外归云的博客园] 问题:把选中行的ID统计出来,组成一个数组传给后台(选中行的特点:class为danger) 办法如下: // 多选后点击下线按钮 $("#offline&qu ...

随机推荐

  1. SAP HANA SLT 将Oracle表 数据同步到HANA数据库

    简单介绍SLT 同步数据的整个配置过程: 在SLT系统中创建与Oracle的链接 在HANA监控平台上,创建Configuration 创建表的同步作业 ——————————————BEGIN———— ...

  2. ASP.NET多线程下使用HttpContext.Current为null解决方案

    多线程或者异步调用中如何访问HttpContext? 前面我还提到在APM模式下的异步完成回调时,访问HttpContext.Current也会返回null,那么此时该怎么办呢? 答案有二种:1. 在 ...

  3. 【AOS应用基础平台】完好了AOS标签库,和标准标签库完美兼容了

    [金码坊AOS开发平台]今天①完好了AOS标签库,和标准标签库完美兼容了.②新开发了依据子页面动态生成主页面的二级导航菜单功能.#AOS开发平台#

  4. 部分 CM11 系统 Android 平板执行植物大战僵尸 2 黑屏的解决的方法

    原文 http://forum.xda-developers.com/showthread.php?t=2755197 部分 CM11 系统的 Android 平板(比如三星 GT-P5110 )执行 ...

  5. SQL Server与Oracle对比学习:权限管理(二) 一些有趣的比喻

    http://blog.csdn.net/weiwenhp/article/details/8094739 目录(?)[-] SQL Server权限管理 login 与user的区别 角色role ...

  6. JAVA IO之管道流总结大全(转)

    要在文本框中显示控制台输出,我们必须用某种方法“截取”控制台流.换句话说,我们要有一种高效地读取写入到System.out和 System.err 所有内容的方法.如果你熟悉Java的管道流Piped ...

  7. PureMVC(JS版)源码解析(五):SimpleCommand类

          之前我们对PureMVC中涉及到观察者模式的三个基本类(Notification/Observer/Notifier)进行了分析,接下来将对PureMVC源码中的其他类进行分析,首先我们讲 ...

  8. a标签中的href="#"与href="javascript:void(0)"区别

    转自http://blog.csdn.net/fightplane/article/details/5190037 <a href="#"> 点击链接后,页面会向上滚到 ...

  9. HDU 4336 Card Collector(容斥)

    题意:要收集n种卡片,每种卡片能收集到的概率位pi,求收集完这n种卡片的期望.其中sigma{pi} <=1; 思路:容斥原理.就是一加一减,那么如何算期望呢.如果用二进制表示,0表示未收集到, ...

  10. HDU-1012(水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1012 分析:就按题目给的公式一步步输出就行了. #include<stdio.h> #include ...