Scala swing table - 捕获列点击
我对 swing 和 scala 都很陌生,但我试图捕获在 scala.swing.Table 中单击列时的情况,但我一直无法弄清楚如何执行此操作。可以在scala中完成吗?我仍在学习如何阅读 scala API,因此任何见解都会有所帮助,
I am pretty new to both swing and scala, but I am trying to capture when a column is clicked in a scala.swing.Table and I have been unable to figure out how to do this. Can it be done in scala? I am still learning how to read the scala API, so any insight would be helpful,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来 Scala Swing 尚不支持表头事件,因此您可能需要执行类似以下操作,将鼠标侦听器直接添加到 JTableHeader。
我确信有一种优雅的方法来创建 scala.swing.Publisher 将侦听器与 listenTo 和 reactions 机制集成,它只是取决于是否值得付出额外的努力。
此外,我发现 TableColumnSelected 事件提供的范围信息相当奇怪,它包含从当前单击到不同列中的上一次单击的连续列索引。也许我错过了一些关于原因的事情。
It looks like Scala Swing doesn't support table header events yet, so you might have to do something like the following which adds a mouse listener directly to the JTableHeader.
I'm sure there is an elegant way to create a scala.swing.Publisher to integrate the listener with the listenTo and reactions mechanism, it just depends if it is worth the extra effort.
Additionally I find the range information provided by the TableColumnSelected event rather strange, it contains contiguous column indices from the current click to the previous click in a different column. Perhaps I'm missing something as to why.
我能够采用 Don Mackenzie 的示例并使用 Publisher 和 Reactor 生成一些东西。
I was able to take the example by Don Mackenzie and produce something using a Publisher and Reactor.
请不要编写自己的表格排序实现 - 请改用 GlazedLists 。你会感谢我的。您可能需要使用标准 JTable 而不是 swing.Table,但它可以处理您必须执行的所有排序和过滤操作。
Please don't write your own implementation of table sorting - use GlazedLists instead. You will thank me. You'll probably need to use a standard JTable rather than a swing.Table, but it can handle all of the sorting and filtering you will ever have to do.