使用 SwingX 对 JXTable 进行排序
我正在使用来自 SwingX 组件的 JXTable
。如果我使用 setSortable(boolean flag) 方法,那么它将启用或禁用所有列的排序。
根据我的要求,我想禁用几列的排序并启用其他列的排序。
任何人都可以帮助实现这个功能吗?
感谢您的回复。您可以帮助我使用 setSorterClass(String sorterClassName)
禁用一列的排序吗?你能给我任何代码示例吗?这对我很有帮助。
I am using JXTable
which is from SwingX components. If I use setSortable(boolean flag)
method then it will enable or disable sorting for all columns.
As of my requirement I want to disable sorting for a few columns and enable sorting for other columns.
Can anyone help achieve this functionality?
Thanks for your reply. Can you help me with using setSorterClass(String sorterClassName)
to disable sorting for one column? Could you give me any code examplex? It will be very helpful for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SwingX 支持 TableColumnExt 级别的每列可排序属性。它的默认值为 true,在列创建后禁用它
或者在创建时使用自定义 ColumnFactory,如
JXTable 将负责将列属性同步到排序器,前提是它的类型为 SortController(这是默认值)
SwingX supports a per-column sortable property on the level of the TableColumnExt. It's default value is true, to disable it after column creation
Or at creation time, use a custom ColumnFactory, like
JXTable will take care of synchronizing the column property to the sorter, provided it is of type SortController (which is the default)
我认为,至少根据我在网上找到的信息,你可以通过设置来实现它
该列的
setSorterClass(null)
。我们可以在 缓存的网站,如 swinglabs 教程页面似乎已关闭,我敢打赌这与 java.net 服务最近的混乱有关。
“JXTables 默认情况下启用列排序。您可以使用 setSortingEnabled(boolean allowedSort) 禁用所有列排序。您还可以通过使用带有空排序器类名的 setSorterClass(String sorterClassName) 禁用对单个列的排序。”
就我个人而言,我认为没有必要阻止用户对选定的表列进行排序。无论如何,如果用户想要对列进行排序,他/她应该能够这样做,最后我相信最好允许用户多做少做,当然,当涉及到他/她可以做什么的细节时控制在他/她的视野中。
I think, at least according to what I have found on the net you can achieve it by setting
setSorterClass(null)
for that column.As we can read on the cached web site, as swinglabs tutorial page appears to be down, I bet it has something to do with the recent mess on the java.net service.
"JXTables have column sorting turned on by default. You can disable all column sorting using setSortingEnabled(boolean allowSort). You can also disable sorting on a single column by using setSorterClass(String sorterClassName) with a null sorter class name."
Personally, I think there is no point to block user from sorting on a selected table column. Anyway if a user wants to sort a column he/she should be able to do so, in the end I believe it is better to allow a user for more then less, of course when it goes to such details as what he/she can control in his/hers view.
我认为你应该看看 TableRowSorter API< /a> 并查看 JXTable 是否支持它,例如:
TableRowSorter 有一个 API 方法 isSortable():
I think you should have a look at TableRowSorter API and see whether JXTable supports it like:
TableRowSorter has an API method isSortable():