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
} }
}
- jQuery DataTables 获取选中行数据
如题 想获取操作 DataTables 获取选中行数据 案1.主要是利用 js getElementsByTagName 函数 然后对获取到的tr 进行操作 如下 function getChec ...
- jqgrid 获取选中行主键集合
如何获取选中行的主键集合呢? 使用 getGridParam(selarrrow) 方法可获取所有选中行的主键集合. 注意:此处的主键集合是指-设置为主键的列(key: true).再次提醒:一个j ...
- gridview获取选中行索引及当前行数据
gridview获取选中行索引及当前行数据 一.非直接绑定数据: <!--前台传值--> <asp:TemplateField HeaderText="操作"&g ...
- EasyUi DataGrid 获取选中行的checkbox
EasyUi DataGrid 获取选中行的checkbox var checked = $(":checkbox[name=ID]:checked"); console.log( ...
- datagrid如何获取选中行的索引
//datagrid获取选中行 var row =baseSelectgrid.datagrid('getSelected'); // 获取被选中行的索引 index var index=baseSe ...
- DHtmlx组件获取选中行的某一列对应的值
最近刚刚接触DHtmlx这个js组件,对它还不是太了解,还在学习中,算是记录自己学习该组件的历程吧. 首先xml文件里有一个grid,有对应的checkbox,通过 var selectedId = ...
- bootstrapTable:获取选中行的数据
必须要有checkbox:true和singleSelect:true,然后就可以通过var row=$("#mytab").bootstrapTable('getSelectio ...
- easy ui datagrid 获取选中行的数据
取得选中行数据: var row = $('#tt').datagrid('getSelected'); if (row){ alert('Item ID:'+row.itemid+" Pr ...
- 如何用jQuery获取选中行固定列的数据
[本文出自天外归云的博客园] 问题:把选中行的ID统计出来,组成一个数组传给后台(选中行的特点:class为danger) 办法如下: // 多选后点击下线按钮 $("#offline&qu ...
随机推荐
- Command-line interface
A command-line interface (CLI), also known as command-line user interface, console user interface, a ...
- 把谷歌等webkit内核浏览器变为输入文本编辑器的方法
只需要在地址栏输入 data:text/html, <html contenteditable> 回车后即可看到效果
- centos中使用python遇到的几个问题
用python搞了一个从excel中读取cobbler节点信息并加入cobbler中的脚本,运行的过程中出了不少问题,这里记录下来,方便日后查找! 一.yum install python,我通过这个 ...
- richTextBoxBulletClass
设置和获取选中的样式为 1. 2. 3. #region 数字序列 1. 2. 3. 4. 5. ... private bool bOrder = false; public bool Select ...
- ViewPager的用法和实现过程
看图先: 页面中填充内容是随机关键词飞入和飞出动画效果,随后会更新,如今请先无视吧 首先是 导入jar包 下载地址:android-support-v4.jar 布局文件中加入v ...
- 如何调试PHP的Core之获取基本信息 --------风雪之隅 PHP7核心开发者
http://www.laruence.com/2011/06/23/2057.html https://github.com/laruence PHP开发组成员, Zend兼职顾问, PHP7核心开 ...
- 最简单的自定义适配器adapter
下面是一个非常简单的自定义适配器的总体源码,从这个源码入门,就可以慢慢学会适配器了 适配器的作用: 完成数据和界面控件的绑定,把数据绑定到界面的现实控件条目上(对于listView,应该是listVi ...
- windows 下rabbitmq 安装---转载
原文地址:http://blog.sina.com.cn/s/blog_7cc0c8cc0101mb4a.html 1.下载并安装erlang,http://www.erlang.org/downlo ...
- 5 Ways to Use Log Data to Analyze System Performance--reference
Recently we looked across some of the most common behaviors that our community of 25,000 users looke ...
- 墙裂推荐 iOS 资源大全
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...