Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对表进行排序会中断TableRowListener吗?_Java_Swing_Sorting_Jtable_Listeners - Fatal编程技术网

Java 对表进行排序会中断TableRowListener吗?

Java 对表进行排序会中断TableRowListener吗?,java,swing,sorting,jtable,listeners,Java,Swing,Sorting,Jtable,Listeners,我有一个带有ListSelectionListener的可排序默认表模型,它侦听双击,然后打开特定列的详细信息视图。但是,当我对列进行排序时,监听器就不再工作了 JTable foosTable = new JTable(model); TableRowSorter<TableModel> fooSorter = new TableRowSorter<TableModel>(model); foosTable.setRowSorter(fooSorter); ListSe

我有一个带有ListSelectionListener的可排序默认表模型,它侦听双击,然后打开特定列的详细信息视图。但是,当我对列进行排序时,监听器就不再工作了

JTable foosTable = new JTable(model);
TableRowSorter<TableModel> fooSorter = new TableRowSorter<TableModel>(model);
foosTable.setRowSorter(fooSorter);
ListSelectionModel listMod = foosTable.getSelectionModel();
listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionListener barListener = new ListSelectionListener(foosTable);
listMod.addListSelectionListener(barListener);
JTable foosTable=新的JTable(模型);
TableRowSorter Foossorter=新的TableRowSorter(型号);
foosTable.setrowserter(fooserter);
ListSelectionModel listMod=foosTable.getSelectionModel();
listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionListener barListener=新建ListSelectionListener(foosTable);
listMod.addListSelectionListener(barListener);

我从未使用过TableRowListener,它似乎只有一个
项更改
事件。我通常坚持标准挥杆。将鼠标侦听器添加到表中,获取单击事件的位置,然后处理它

 jTable.addMouseListener(new java.awt.event.MouseAdapter() {
     public void mouseClicked(java.awt.event.MouseEvent evt) {
         Point p = new Point(evt.getX(), evt.getY());
         int col = jTable.columnAtPoint(p);
         int row = jTable.rowAtPoint(p);
         if (evt.getButton() == MouseEvent.BUTTON1)
         {
            if (evt.getClickCount() >= 2)
            {
               ...
               ...
            }
        });
编辑 设置a:

TableRow分拣机=
新的TableRow分拣机(yourJTableModel);
jTable.setRowSorter(分拣机);
因为您正在更改行顺序,所以需要使用 获取视图的正确模型数据


对于更复杂的排序/筛选需求,您可能需要尝试。

您可以显示一些代码吗?谢谢。我从来没有听说过桌游听众。@camickr。它似乎在包org.smir.util.table中,我自己从来没有使用过它。ListSelectionListener不侦听双击,它只选择一行。请问一个适当的问题。既然你已经两次问不出解决问题所需的所有信息,那么你真的需要发布一个SSCCE()来演示问题,这样我们就不必一直猜测你到底在问什么。我们没有时间猜测你的真正意思。这解决了我的问题,我拥有的是一个实现ListSelectionListener并继承MouseApter的类。
  TableRowSorter<YourJTableModel> sorter =
        new TableRowSorter<YourJTableModel>(yourJTableModel);
   jTable.setRowSorter(sorter);