在RowSort操作之后执行操作 [英] Performing an action after a RowSort operation

查看:90
本文介绍了在RowSort操作之后执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JTableTableRowSorter,我想在完成排序后在 上执行操作.我一直在浏览网络,到目前为止,我还没有碰到太多运气.

I have a JTable and a TableRowSorter which I'd like to perform an operation after a sort is finished. I've been browsing the net, and so far I haven't had much luck.

最初,我以为只有RowSorterListener可以解决问题,但不幸的是,排序完成后它没有执行操作.

Initially I thought just a RowSorterListener would do the trick, but unfortunately it doesn't perform the operation after the sort is finished.

JTable标头中添加MouseListener可能有效,但是解决方案并不十分优雅.

Adding a MouseListener to the JTable header could work, but the solution isn't terribly elegant.

有人有什么想法吗?

感谢一堆!

编辑(来自注释):在自定义TableModel类中扩展了AbstractTableModel的方法中添加了以下内容.在自定义TableModel类中设置/指定JTable时,将调用此方法.

Edit (from comment): The following is added in a method inside a custom TableModel class which extends AbstractTableModel. This method is invoked whenever the JTable is set/specified in the custom TableModel class.

sorter.addRowSorterListener(new RowSorterListener() {
    @Override public void sorterChanged(RowSorterEvent rowsorterevent) {
        rebuildMItems(); // The method which executes
    }
});

推荐答案

两种可能性:

  1. 我看到您有一个自定义的RowSorter.您不能简单地在sort()方法的末尾添加对您的操作的调用吗?

  1. I see you have a custom RowSorter. Couldn't you simply add a call to your operation at the end of the sort() method?

换句话说,您可以添加此内容吗?

In other words, can you add this:

@Override
public void sort() {
    super.sort();
    doSomethingAfterSortingIsDone();
}

到您的分拣机?

您当前的方法(在RowSorterListener中执行)执行两次操作:一次用于SORT_ORDER_CHANGED,一次用于SORTED.您可以检查事件的类型仅在正确的时间执行操作?

Your current method (doing it in a RowSorterListener) performs the operation twice: once for SORT_ORDER_CHANGED and once for SORTED. Can you check the event's type and only perform the operation at the correct time?

这篇关于在RowSort操作之后执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆