简体   繁体   English

在JTable中单独合并列标题

[英]Merging column headers alone in JTable

Is there a way to merge column headers on click of a button but the values in the cell should get appeneded with each other? 有没有一种方法可以在单击按钮时合并列标题,但是单元格中的值应该彼此附加?

For instance: 例如:

10      15      20     25     30
A       B       C      D      E
B       C       D      A      E

10              20            30
AB              CD            E
BC              DA            E

Actually the value A represents 10-15 B represents 15-20 and so on.Is this possible in JTable? 实际上A代表10-15,B代表15-20,依此类推,在JTable中可以吗? Please don't confuse my earlier question with this.Here we try to merge two column headers not cells at the same time we append the values of the cell. 请不要将我之前的问题与此混淆。在此,我们尝试在合并单元格的值的同时合并两个列标题而不是单元格。

You can do whatever you want using the getValueAt(...) and setValueAt(...) methods. 您可以使用getValueAt(...)和setValueAt(...)方法做任何您想做的事情。

So you get the values of the two columns and combine them into a single string and then reset the value in the first column. 因此,您将获得两列的值,并将它们组合为一个字符串,然后在第一列中重置该值。 Then you set the second column to the empty string. 然后,将第二列设置为空字符串。

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

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