JTable 真的让我很郁闷!高手~请进! 我想获得通过鼠标在JTable中点击后的数据行中的数据!我为JTable 添加了MouseListener监听器,可是没有达到目地!还有就是怎样让用户一次只能选中一行数据! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用侦听鼠标,只需要侦听表格的选中行就可以了。this.table = new JTable();//只能选中一行this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);//注册选择侦听,其中this是实现了ListSelectionListener的对象this.table.getSelectionModel().addListSelectionListener(this);……public void valueChanged(ListSelectionEvent e) { if(e.getValueIsAdjusting()) return; if(e.getSource().equals(this.table.getSelectionModel())){ if(!this.table.getSelectionModel().isSelectionEmpty()){ //获取选中行号 int selectRow = this.table.getSelectRow(); //然后想干嘛干嘛 …… } }} 使用鼠标监听也可以实现的,getSelectRows就可以了得到行号不过如果是已经排过序的JTable,需要注意这样得到的行号可能需要转换一下才是model中的行号 泛型的<?>是什么意思 Object流小问题? 紧急求救 又没分了,再问一个简单的问题 关于对JAVA对底层操作的不解? 数据结构的书:) jb与tomcat的集成 如何使用 rmic 命令创建 *_stub.class文件????急盼复!!! 请问一小段代码 截取AT命令返回的信息 JarInputStream复制jar,输出的jar比原来的大 关于JTABLE表头宽度变化的事件
this.table = new JTable();
//只能选中一行
this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//注册选择侦听,其中this是实现了ListSelectionListener的对象
this.table.getSelectionModel().addListSelectionListener(this);
……
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
if(e.getSource().equals(this.table.getSelectionModel())){
if(!this.table.getSelectionModel().isSelectionEmpty()){
//获取选中行号
int selectRow = this.table.getSelectRow();
//然后想干嘛干嘛
……
}
}
}
不过如果是已经排过序的JTable,需要注意这样得到的行号可能需要转换一下才是model中的行号