Swing JTable自定义渲染 [英] Swing JTable custom rendering

查看:169
本文介绍了Swing JTable自定义渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有没有JavaFx的这种编程任务,而是Java Swing。我意识到我的知识仍然有限。

I have this kind of progamming task without JavaFx, instead it's Java Swing. I realized my knowledge is still limited.

我有一个JTable。
但是,在这个JTable中,我需要一个客户Cell渲染器。
目标是制作这种JTable:示例图片

I have one single JTable. But, within this JTable I need a custome Cell Renderer. The goal is to make this kind of JTable: Example image

我目前的解决方案是:示例图片

My current solutions are: Example Image


  1. 创建单个JTable:

    • 获取每个列并使用自定义渲染器(下面)设置其CellRenderer。


  • 在getTableCellRendererComponent中返回不同的JPanel
    使用开关案例的方法(作为列数)。

下班后,小时,我认为我目前的解决方案是相当艰巨的任务。因此,我的问题是:

After hours, and hours, I think my current solutions is quite daunting tasks. Thus, My question is:

创建此Custom JTable以实现上述主要目标的最简单方法是什么?

What are the simplest method of creating this Custom JTable to achieve the main goal as mentioned above?

推荐答案

我一直面临这个问题,我决定自己做。扩展表的现有实现,为表中的内容添加一些概念,并为此编写一些编辑器/侦听器。所有相同,但有一个treetable。

I've been facing this problem for a while, and I decided to do it myself. Extending the existing implementation of a table, adding some concepts for what I expect from a table, and writting some editors/listeners for that. All the same, but with a treetable.

我正在开展这个名为 SUMI

它包含一个java包( ar.com.tellapic.sumi.treetable )这是 SwingLabs 的noreferrer> JXTreeTable

It contains a java package (ar.com.tellapic.sumi.treetable) that is an extension of a JXTreeTable from SwingLabs.

该项目正在开发中,我还没有提供任何文件。您可以通过创建渲染器并根据需要创建编辑器来执行所需操作,最后将操作附加到每个对象。

The project is being developed and I didn't provide any documentation yet. You can do what you want by creating a renderer and if needed, an editor, for lastly attaching actions to each object.

如果您决定使用它并且需要帮助给我发电子邮件,我会毫无问题地帮助你。

If you decide to use it and you need help, email me, I'll help you without any problem.

或者,你可以自己阅读来源。

Or, you could read the source by your own.

问候,

编辑(再次):

清除一点点这个答案,我刚刚在项目维基并将相关代码放在那里。如果有人觉得应该在这里插入代码,请告诉我。

To clear a little bit this answer, I've just created a wiki page in the project wiki and put the relevant code there. If someone feels that the code should be inserted here, please let me know.

基本上,我试着解释如何找到渲染器/编辑器问题的直接解决方案可以通过使用我的项目的一部分找到使用 JTable 来满足您的具体需求,以便得到这样的结果:

Basically, I try to explain how to find a straight solution to the renderer/editor problems you may find using JTable with your specifics needs by using part of my project, in order to get something like this:

请注意,屏幕截图是在点击相应的勾选按钮后拍摄的。

Note that the screenshot was taken after clicking on the respective tick-button.

这篇关于Swing JTable自定义渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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