JTableHeader可以跨多列吗? [英] Can `JTableHeader` span over multiple columns?

查看:114
本文介绍了JTableHeader可以跨多列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间进行搜索,但只找到了GroupableHeader代码.我需要在2列JTable中的2列上有一个标头.

I've spent quite some time searching for this and I've only found the GroupableHeader code. I need one header over 2 columns in a 2 column JTable. How can this be done without the use of the infamous GroupableHeader, while keeping the default look and feel of the `JTableHeader?

这是我所想的图形表示:

This is a graphical representations of what I have in mind:

_________________________
|     Table Header      |
|-----------------------|
|           |           |
|-----------|-----------|
|           |           |
|-----------|-----------|

推荐答案

这取决于您要实现的目标.

This depends on what eaxctly you want to achieve.

我通过创建自己的JTableHeader(实际上只是一个JPanel)做了类似的事情.

I did something similar by creating my own JTableHeader, which was essentially just a JPanel.

在它上面,我在要排成一列的列上方的第一行上放置了"group"标题.

On it I placed "group" headers on the top row, over the columns I wanted to "group".

然后我作弊并使用了现有表格的行标题,并将其添加到标题下方的第二行.

Then I cheated and used the existing tables row header and added it to the second row below the header.

这需要一些技巧,因为您需要知道要分组/跨度的列及其宽度.您还需要监视其宽度的变化并适当地更新标题.

This requires some slight of hand, as you need to know the columns you want to group/span and their widths. You also need to monitor for changes in their widths and update the header appropriately.

我见过的大多数实现都使用其自己的UI实现,我个人不喜欢这种方法,因为它会使您正在使用的外观失去作用.

Most of the implementations I've seen use their own UI implementation, personally I don't like this as it undoes the work of the look and feel you're using.

您可以查看,它演示了许多有趣的事情您可以使用JTable以及多列跨度进行操作,但是同样,它使用自己的UI来使其正常工作.

You could have a look at this which demonstrates a number of interesting things you can do with JTables as well multi-column spanning, but again, it's using it's own UI to get it to work.

我们开始在工作中使用的实现以相同的方式工作,而我遇到的问题是,您可以在组标题中看到鼠标调整大小光标,对我来说,这并不是您真正想要的用户看

The implementation we've begin using at work works in the same way and the problem I have with it is that you can see the mouse resize cursor within the group header, which, to me, isn't really what you want the user to see

这篇关于JTableHeader可以跨多列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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