简体   繁体   English

JTable与jgoodies排序麻烦

[英]JTable with jgoodies sorting trouble

I've got a blocking problem with the sorting functionality of a JTable; JTable的排序功能存在阻塞问题; this made stall the development of the spare time open source project for 4 months now. 这使业余时间开源项目的开发停滞了四个月。 Hope to be pointed into the right direction here. 希望在这里指出正确的方向。

Context: I'm working on extending the functionality of the ps3mediaserver to add a media library with pms-mlx . 上下文:我正在扩展ps3mediaserver的功能,以使用pms- mlx添加媒体库。 The UI of the media server has been done using swing. 媒体服务器的UI已使用swing完成。

Problem: When clicking on a column header in the JTable, a seemingly random column gets sorted instead of the one having been clicked. 问题:单击JTable中的列标题时,似乎是随机的列将被排序,而不是被单击的列。

Current implementation: Here's the description of the different components and classes being used for the implementation: 当前实现:这是用于实现的不同组件和类的描述:

  • ETable : As alternate row colours aren't supported by default in the JTable, I've switched to the ETable extending the JTable. ETable :由于默认情况下JTable不支持备用行颜色,因此我改用了ETable来扩展JTable。 Source comes from here 来源来自这里
  • FileDisplayTable : This is the class creating the table. FileDisplayTable :这是创建表的类。 In the init() method, the sorting is being enabled with 'table.setAutoCreateRowSorter(true);' 在init()方法中,使用“ table.setAutoCreateRowSorter(true);”启用排序。
  • FileDisplayTableCellRenderer : Exists to always align cell content on the left FileDisplayTableCellRenderer :存在以始终在左侧对齐单元格内容
  • FileDisplayTableColumnModel : Does some mapping between internal types and column names FileDisplayTableColumnModel :在内部类型和列名之间进行一些映射
  • FileDisplayTableAdapter : This class implements com.jgoodies.binding.adapter.AbstractTableAdapter to map the objects with the table columns. FileDisplayTableAdapter :此类实现com.jgoodies.binding.adapter.AbstractTableAdapter来将对象与表列映射。

Possible solutions: 可能的解决方案:

  • Preferably, I'd like to keep the current implementation and figure out how to correct the sorting, but I doubt someone can help me out with that!? 最好是,我想保留当前的实现,并弄清楚如何纠正排序,但是我怀疑有人可以帮我解决这个问题! Additionally their are some bits of code I had to add because of strange behaviours; 另外,由于某些奇怪的行为,我不得不添加一些代码。 they're commented in the code 他们在代码中被注释
  • The alternate option would be to change the JTable for another control altogether. 另一种选择是完全更改另一个控件的JTable。 I've made some research but didn't find the solution I was hoping for. 我进行了一些研究,但没有找到我想要的解决方案。 The constraints are that 约束是
    • it must be embeddable in a swing UI 它必须可嵌入到摆动用户界面中
    • preferably it should support data bindings 最好它应该支持数据绑定
    • support alternate row colours 支持替代行颜色
    • row sorting 行排序

At some point it will be possible to open an editing dialogue, where the content of the row has to be retrieved, can be edited and when saved the row has to be updated. 在某个时候,可以打开一个编辑对话框,其中必须检索该行的内容,可以对其进行编辑,并且在保存时必须更新该行。

Before reworking the entire thing I'd like to be sure the component will be able to handle all I want to do with it. 在重做整个事情之前,我想确保该组件将能够处理我要使用它进行的所有操作。

I'm more used to create GUIs using .NET in Visual Studio. 我更习惯在Visual Studio中使用.NET创建GUI。 It's quite different and a lot more difficult to do the same with swing. 摇摆是完全不同的,并且要执行相同的操作要困难得多。 Please show me I'm wrong :) 请告诉我我错了:)

[edit] If someone is willing to reproduce the problem, either get the source or the binaries, launch the application, navigate to the media library tab. [edit]如果有人愿意重现该问题,请获取源文件或二进制文件,启动应用程序,导航至“媒体库”选项卡。 In the Genral section import some videos by adding some video files. 在“一般”部分中,通过添加一些视频文件来导入一些视频。 Go to the library section, click on apply to refresh the list and try to sort the table. 转到库部分,单击“应用”以刷新列表并尝试对表进行排序。

It may be useful to know that JTable columns can be dragged by the user. 知道用户可以拖动JTable列可能会很有用。 As a result, the view ( JTable or a subclass) and model (an implementation of TableModel ) may have different column numbers. 结果,视图( JTable或子类)和模型( TableModel的实现)可能具有不同的列号。 Similarly, a RowSorter may affect the order or number of rows in the view as compared to the model. 同样,与模型相比, RowSorter可能会影响视图中行的顺序或数量。 The related conversion methods are mentioned in How to Use Tables: Sorting and Filtering . 如何使用表:排序和过滤中提到了相关的转换方法。 In particular: "When using a sorter, always remember to translate cell coordinates." 特别是:“使用分类器时,切记转换单元格坐标。”

Addendum: As an alternative, consider org.netbeans.swing.etable.ETable or it's subclass org.netbeans.swing.outline.Outline , depicted here . 附录:作为替代方案,考虑org.netbeans.swing.etable.ETable或它的子类org.netbeans.swing.outline.Outline ,如此处所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM