JXTable列排序在1.0和1.6之间更改 [英] JXTable column sorting changes between 1.0 and 1.6

查看:101
本文介绍了JXTable列排序在1.0和1.6之间更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我们更新到JDK1.6以来,我最近将应用程序中的SwingX库从1.0版本更新到1.6.2.我知道排序已更改为重新使用JDK 1.6中引入的某些Core JDK组件.

I recently updated the SwingX library in an application from version 1.0 to 1.6.2 since we updated to JDK1.6 . I know the sorting has been changed to re-use some of the Core JDK components which were introduced in JDK 1.6 .

但是,在1.0版中,可以通过单击标题来对列进行排序,随后的单击可以还原排序顺序,而Shift单击可以删除排序并还原为原始顺序.在更新到1.6.2版后,将不再出现shift单击行为.

However, in version 1.0 it was possible to sort a column by clicking on the header, subsequent clicks reverted the sort order, and shift click removed the sorting and reverted back to the original order. After the update to version 1.6.2, the shift click behavior is no longer present.

少量样品

import org.jdesktop.swingx.JXTable;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import java.awt.EventQueue;

public class JXTableSortingTest {
  public static void main( String[] args ) {
    EventQueue.invokeLater( new Runnable() {
      public void run() {
        initUI();
      }
    } );
  }

  private static void initUI(){
    JFrame testFrame = new JFrame( "TestFrame" );
    JXTable table = new JXTable(  );
    DefaultTableModel model =
        new DefaultTableModel( new Object[][]{ new Object[]{"A"}, new Object[]{"B"}, new Object[]{"C"}, new Object[]{"D"}, new Object[]{"E"} }, new Object[]{"Click me"} );
    table.setModel( model );

    testFrame.getContentPane().add( new JScrollPane( table ) );

    testFrame.pack();
    testFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    testFrame.setVisible( true );
  }
}

在1.0版中运行此示例可以通过在标题上单击并单击来删除列排序,而在1.6.2版中,此列不再起作用.

Running this sample with version 1.0 allows to remove the column sorting with a shift-click on the header, and with the 1.6.2 version this no longer works.

我检查了文档,但没有遇到任何东西可以重新打开此行为.因此,在开始添加此功能之前,我在这里询问了是否有人知道重新引入Shift-Click行为的简便方法

I checked the docs but did not encounter anything to switch this behavior back on. So before I start adding this functionality I though I asked it here if anybody knows an easy way to re-introduce the shift-click behavior

推荐答案

不支持,至少不完全与1.0中的方式不同.

it's not supported, at least not in the exact same way as in 1.0.

默认支持可以提供的最接近的功能是在JTable上设置sortOrderCycle属性,然后重复单击将在被单击列的这些状态之间循环:

The nearest you can come with default support is to set the sortOrderCycle property on the JTable, then repeated clicks will cycle through those states for the column which is clicked:

table.setSortOrderCycle(ASCENDING, DESCENDING, UNSORTED);

这与旧的行为不同之处在于,旧的已删除的 all 进行了排序-如果需要,可以使用重置排序键的自定义mouseListener来解决.

This differs from the old behaviour in that the old removed all sorts - if you need that, a custom mouseListener which resets the sort keys is the way to go.

另外,您可以考虑在SwingX问题跟踪器中提出功能请求,并在SwingLabs论坛上开始讨论:我们决定放弃它的主要原因是与核心行为的一致性.而且没有人吠叫,它就留在那儿了:-)

Plus you might consider filing a feature request in the SwingX issue tracker and start a discussion over on the SwingLabs forum: the main reason we decided to drop it, was consistency with core behaviour. And as nobody barked, it was left at that :-)

这篇关于JXTable列排序在1.0和1.6之间更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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