Topic: 如何用JTable设置表头多行

  Print this page

1.如何用JTable设置表头多行 Copy to clipboard
Posted by: kylin
Posted on: 2004-10-18 10:25

例如下图
不知道该如何出现象下面的表头,跪谢各位大虾指点,不胜感激

——————————————————————————
职业 | 日期 | 代码 |
--------------------------| | |
医生 | 律师 | | |
————————————————————|——————|

2.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-18 10:40

不好意思,刚才贴错了,现在重贴

表头.bmp (576.05k)

3.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-18 11:01

不好意思,又来一次

4.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: floater
Posted on: 2004-10-18 11:14

http://www.physci.org/codes/tame/index.jsp

get Nobuo's zip file, it has more than you need.

5.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: floater
Posted on: 2004-10-18 11:15

don't cross post!!!

6.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-18 15:22

我下载了,运行了,但是“MultiWidthHeaderExample”这个类运行出错,我看了半天,没看出什么头绪,请总版主大人再帮帮忙,谢谢:)

7.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-18 21:55

那个例子的代码修正如下:

public class GroupableHeaderExample extends JFrame {

GroupableHeaderExample() {
super( "Groupable Header Example" );

DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{
{"119","foo","bar","ja","ko","zh"},
{"911","bar","foo","en","fr","pt"}},
new Object[]{"SNo.","1","2","Native","2","3"});

JTable table = new JTable( dm ) {
protected JTableHeader createDefaultTableHeader() {
return new GroupableTableHeader(columnModel);
}
};
TableColumnModel cm = table.getColumnModel();
ColumnGroup g_name = new ColumnGroup("Name");
g_name.add(cm.getColumn(1));
g_name.add(cm.getColumn(2));
ColumnGroup g_lang = new ColumnGroup("Language");
g_lang.add(cm.getColumn(3));
ColumnGroup g_other = new ColumnGroup("Others");
g_other.add(cm.getColumn(4));
g_other.add(cm.getColumn(5));
g_lang.add(g_other);
GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
header.addColumnGroup(g_name);
header.addColumnGroup(g_lang);

TableCellRenderer renderer = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
};

TableColumnModel model = table.getColumnModel();
for (int i=0;i<model.getColumnCount();i++) {
model.getColumn(i).setHeaderRenderer(renderer);
}
JScrollPane scroll = new JScrollPane( table );
getContentPane().add( scroll );
setSize( 400, 120 );
}

public static void main(String[] args) {
GroupableHeaderExample frame = new GroupableHeaderExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}
}

应该没有问题了。

8.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-19 09:38

真是太感谢了,其实我也知道是renderer的问题,但是就是不知道该怎样去向model中添加renderer,我想知道renderer, table, tablemodel, tableColumnModel,等等(可能没列全)这些类再构造表的时候会起什么作用,他们之间的关系,以及他们执行的顺序,一句话:就是想理解他们在构造table是所扮演的角色,多谢帮忙,

9.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-19 13:20

我发现tame写得很不错,有机会就好好的研究一下,不过据说那个作者向一缕轻烟地消失在空中了,真是遗憾!

10.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: floater
Posted on: 2004-10-19 22:16

you've been jumping up and down here recently, really have time to kill, ...

Just kidding, keep up the good work...

Here is a credit, you should be able to get into the restricted area ...

cheers,
floater - just a floater in UFO - unknown enemy, not a flying cow ...

11.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-19 22:40

SmileBig SmileCoolShyBig SmileSmile
thanks for your credit.

12.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-20 10:29

kavinwang :您好
我发现表头和所对应的列不能够对齐,这是怎么一回事

13.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-20 12:56

原因为在先前的header中已经考虑过margin的问题了,而后面重复累加了此margin。你可以更改GroupableTableHeaderUI的paint方法,删除对margin的累加。
本来我已经看到这种不能对齐的情况,没想到你真的来问。不过我还是鼓励你自己解决,实在不行的话,在来此问。
具体代码如下:

public void paint(Graphics g, JComponent c) {
Rectangle clipBounds = g.getClipBounds();
if (header.getColumnModel() == null) return;
// ((GroupableTableHeader)header).setColumnMargin();
int column = 0;
Dimension size = header.getSize();
Rectangle cellRect = new Rectangle(0, 0, size.width, size.height);
Hashtable h = new Hashtable();
// int columnMargin = header.getColumnModel().getColumnMargin();

Enumeration enumeration = header.getColumnModel().getColumns();
while (enumeration.hasMoreElements()) {
cellRect.height = size.height;
cellRect.y = 0;
TableColumn aColumn = (TableColumn)enumeration.nextElement();
Enumeration cGroups = ((GroupableTableHeader)header).getColumnGroups(aColumn);
if (cGroups != null) {
int groupHeight = 0;
while (cGroups.hasMoreElements()) {
ColumnGroup cGroup = (ColumnGroup)cGroups.nextElement();
Rectangle groupRect = (Rectangle)h.get(cGroup);
if (groupRect == null) {
groupRect = new Rectangle(cellRect);
Dimension d = cGroup.getSize(header.getTable());
groupRect.width = d.width;
groupRect.height = d.height;
h.put(cGroup, groupRect);
}
paintCell(g, groupRect, cGroup);
groupHeight += groupRect.height;
cellRect.height = size.height - groupHeight;
cellRect.y = groupHeight;
}
}
cellRect.width = aColumn.getWidth() ;//+ columnMargin;
if (cellRect.intersects(clipBounds)) {
paintCell(g, cellRect, column);
}
cellRect.x += cellRect.width;
column++;
}
}


14.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-21 14:00

我想改变某一个特定的单元格的背景色或前景色,对于每一列,可以自定义render来指定颜色,但是某一个特定的单元格我却不知道该如何去做,而且我要求动态的根据我的需要随时可以改变它的颜色,想大虾求助

15.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-21 14:26

有个叫做tableCellRender的你可重新实现。
在JTable或者其它的Swing中,灵活到任一个部分都可定制,这也是Swing比swt好的原因(可能不正确),不过你要熟悉一个叫做MVC的设计模式,基本上swing都是建构在这个设计模式上的。

16.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-21 17:22

怎样当修改表格重某个单元格后,焦点离开,怎样判断它的值是否改变(是不是很弱智)

17.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-21 17:32

呵呵,我现在可以实现改变某一个特定的单元格的背景色或前景色了,兴奋ing

18.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-21 18:38

恭喜你,有进步!同时看到你进步我也很开心!

19.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-22 08:56

谢谢:), 还有当修改表格中某个单元格后,焦点离开,怎样判断它的值是否改变,因为当值改变需要作其他的处理

20.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-22 09:28

当修改表格的某个单元内容后,如果不确定,比如回车,实际上,table是不知到的。
你的这个要求我也没有做过,不过可以给点建议:
你可以对cellrender添加事件,当修改时,通知你的事件监听器。

21.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-22 11:47

因为表中某些列是有其他列的值计算出来的,所以我想实现当修改某个单元格后就把相应的变化反映到与值关联的单元格上的,所以我想判断某个单元的值是否被改变,不过我现在不那样做了,我重写了JTable的setValueAt方法,仍然调用原先的方法,在后面添加了我想要做的处理,这样就解决了,

22.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-22 13:00

实际上,table的很多数据上的问题都可以通过talbemodel解决的,tablemodel做的很好,可以自己随便实现。

23.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-22 16:28

焦点再table中,如果按下"tab"健,自动向下一个单元格移动,我想知道这个监听事件是怎样添加的,在哪里做的这些操作,因为我想添加自己的动作

24.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-22 17:59

头痛啊,没想到有这么复杂的表,下面这张图单元格可以对应多行,不知道怎样实现,痛苦中

25.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-22 18:01

头痛啊,没想到有这么复杂的表,下面这张图单元格可以对应多行,不知道怎样实现,痛苦中,请大虾们给点意见,小生这厢有理了

26.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-23 22:08

在tame中好像有几个不同的table分别对应这个表的不同形式,你可把它们结合起来进行实现。
我也只是建立,你这个表格实在是有点复杂。

27.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-25 15:46

tame中MultipleRowHeaderExample这个类好像是实现这个效果的,但是我运行起来却不是这样的,不知道是怎么回事

28.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-25 16:41

那是什么样子?

29.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-25 17:45

我看代码里是这样的
* ----------------------------------------------
* | SNo. |
* ----------------------------------------------
* | | 1 |
* | Name |-----------------------------------
* | | 2 |
* ----------------------------------------------
* | | 1 |
* | |-----------------------------------
* | Language | 2 |
* | |-----------------------------------
* | | 3 |
* ----------------------------------------------
但是实际运行起来是这样的,好像fixedTable没有作用

30.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-26 09:43

在AttributiveCellTableMode中暂时把setDataVector方法的内容用下面的代码替代:

public void setDataVector(Vector newData, Vector columnNames) {
if (newData == null)
throw new IllegalArgumentException("setDataVector() - Null parameter");

dataVector = (newData != null) ? newData : new Vector(0);
columnIdentifiers = (columnNames != null) ? columnNames : new Vector(0);

cellAtt = new DefaultCellAttribute(dataVector.size(),
columnIdentifiers.size());

newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
     TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
}


关于对不齐的问题,解决的方式可以参考上一次的方法,希望你能自己搞定。

31.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-26 14:02

好像是那么一回事,不过还不能满足我的需要,我在研究研究,如果有了新得会贴出来共享一下,呵呵

32.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: hujianso
Posted on: 2004-10-28 11:08

to: kavinwang
你实在太强了!好佩服你啊!你给的那两段代码实在是"厉害",你都是怎么想到的啊,太强了!太强了!太强了!!

33.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-28 14:34

谢谢夸奖!
kylin:你的那个东西有搞定吗?

34.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-10-29 10:28

hujianso说得对,kavinwang的确是太强了,帮了我很大的忙,我都不知道该怎样感激他,如果有机会来南京,我可要好好请他一顿了,呵呵。

现在好像不需要搞那么复杂的表了,只需要表头可以对应多列的,不需要单元格可以对应多行的要求了,不过单元格之间要做处理,我不知道按tab健在表格健移动这个事件在哪里添加的,

35.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: javatool
Posted on: 2004-11-02 10:30

可以联系MSN: javatoolsoft@hotmail.com

36.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xiaoxiaoxia
Posted on: 2004-12-15 09:20

看到这里有位高人,我很开心。我有一个棘手的问题请教一下:
我想使用JTable 实现这样一个功能,选中同行或者同列的几个单元格,可以把它们合并成一个单元格,图示如下:
-----------|-----------|----------|
-----------|-----------|----------|

变为
-----------|----------------------|
-----------|----------------------|

也就是说我想随意合并表格的单元格

能给我个解决思路嘛,谢谢! |

37.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-22 11:13

kylin大师,现在万分紧急,想讨教你的多行表头是怎么实现的?我也要做这样的效果,请帮忙,万分感谢!

38.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-12-22 11:40

你先等等,我先整理一下,马上传上来

39.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-12-22 13:54

xcontinue:你看看t.java或TaxBudget.java的实现,你可以先运行看看效果,不过我可以先贴上t.java的运行的效果图

40.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kylin
Posted on: 2004-12-22 14:02

刚才发的怎么没把代码放上去

test.rar (16.62k)

41.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-25 19:06

请问斑竹:如何给jtable 的cell着不同的颜色?

42.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-25 19:08

请问:kylin怎么给jtable的cell着不同的颜色?jtable好像不能实现这个功能耶
万分着急!

43.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-25 19:12

像这样一幅图如何用jtable实现?表头多行我已实现,但其中有些格子的右边框为红色或者加粗,如何实现呢?万分紧急!

44.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-26 17:11

我搞了如图所示的页面,为什么用了边框以后cell和header对不齐呢?(不用边框的时候我像kavinwang指教的那样改了是可以对得齐的)

45.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: xcontinue
Posted on: 2004-12-28 10:53

怎么没人说话阿?救命啊

46.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-12-28 11:16

我当时是进行硬性的改动,如果你提供边框的话,可能需要再做些改动,如果看到我之前提供的改动的代码,进行后续的改动应该不困难,你可自己试着进行改动!

47.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: ccvcd
Posted on: 2005-01-12 17:39

to:xcontinue
能把你的实现源码发给我一份吗,我现在正需要这个呢,谢谢了。
我的邮箱:ccvcd@sohu.com

48.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: javatool
Posted on: 2005-01-31 13:50

可以试试JavaCellReport http://www.javatoolsoft.com

49.借宝地提问tame.exmple.AnimatedIconHeaderExample [Re: kylin] Copy to clipboard
Posted by: windcao
Posted on: 2005-02-24 15:23

to:kavinwang 佩服佩服佩服佩服佩服佩服佩服佩服佩服佩服佩服佩服
我在调tame的第一个例子AnimatedIconHeaderExample似乎里面并没有用到
tame 的东西。这里面的table getHeaderRenderer() 取出的header是空的。是不是由于jdk升级引起的还没有调查不知道你是否关注过这个例子。共同探讨一下

50.欢迎大家参与tame的重新整理工作,积极讨论 [Re: kylin] Copy to clipboard
Posted by: windcao
Posted on: 2005-02-24 15:35

http://www.cjsdn.net/post/view?bid=46&id=135778&sty=1#135778

51.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: ShiZhen
Posted on: 2005-02-28 19:34

斑竹及各位大虾,在下有理了。
看了这里的文章觉得非常好,尤其是关于表头的设定,收益匪浅。
我现在做JTable的东东,遇到了一个问题哪位能给指点一下?
先谢谢了。
我的table中有一列只能录入数字,当焦点离开该列的某个Cell是我先判断录入的值是不是数字,若不是程序打出错误框,关闭错误框后我想让焦点回到刚才编辑过的Cell,现在我不知道该如何能让焦点回到table中某个指定的Cell。请帮帮忙!

52.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: kavinwang
Posted on: 2005-03-01 08:44

取出刚才输入的cell的位置,再调用相应的方法进行设置

53.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: 杰克逊
Posted on: 2005-03-02 11:46

以身相许吧,呵呵……
有row的randerer自然也有column的randerer,以前每一行的行头有一个rowNo道理是一样的

54.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: zhansy
Posted on: 2005-03-18 22:40

我发现个问题,好像你们写的程序在jdk1。5里面运行时,表头只能显示最下面的一列,这个是什么原因呢???

55.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: seeler
Posted on: 2005-03-30 08:54

厉害,学到东西了

56.Re:如何用JTable设置表头多行 [Re: xcontinue] Copy to clipboard
Posted by: billyzorro
Posted on: 2005-03-30 09:17

代码下载是损坏的,能重发吗? test.rar

57.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: ljy789654
Posted on: 2005-05-10 15:53

我对JAVA的认识不过有一定了解。
想请你帮忙做个小游戏。怎么样?

58.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: mylzw
Posted on: 2005-05-14 19:35

我也发现JDK1.5只显示一行表头,不知道是什么原因啊。
望高手赐教!

59.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: leigh
Posted on: 2005-06-08 15:33

问题应该是出在 AttributiveCellTableModel 的 setDataVector() 方法中调用了 setColumnIdentifiers(), 而 1.5 的 setColumnIdentifiers() 方法中又调用了 setDataVector(),导致堆栈溢出了。

60.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: hyhoo7
Posted on: 2005-06-16 09:43

在jdk15中运行需要修改代码,修改如下:

/* (swing1.1beta3) */
package tame.examples;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.*;

import javax.swing.*;
import javax.swing.table.*;

import tame.table.ColumnGroup;
import tame.table.GroupableTableHeader;
import tame.table.GroupableTableHeaderUI;

/**
<pre>
* |-----------------------------------------------------|
* | | Name | Language |
* | |-----------------|--------------------------|
* | SNo. | | | | Others |
* | | 1 | 2 | Native |-----------------|
* | | | | | 2 | 3 |
* |-----------------------------------------------------|
* | | | | | | |
</pre>
@author Nobuo Tamemasa
@version 1.0 11/09/98
*/
public class GroupableHeaderExample extends JFrame {

GroupableHeaderExample() {
super( "Groupable Header Example" );

DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{
{"119","foo","bar","ja","ko","zh"},
{"911","bar","foo","en","fr","pt"}},
new Object[]{"SNo.","1","2","Native","2","3"});

JTable table = new JTable( dm ) {
protected JTableHeader createDefaultTableHeader() {
return new GroupableTableHeader(columnModel);
}
};
TableColumnModel cm = table.getColumnModel(); //得到列模型,可以取出表头
ColumnGroup g_name = new ColumnGroup("Name");
g_name.add(cm.getColumn(1));
g_name.add(cm.getColumn(2));
ColumnGroup g_lang = new ColumnGroup("Language");
g_lang.add(cm.getColumn(3));
ColumnGroup g_other = new ColumnGroup("Others");
g_other.add(cm.getColumn(4));
g_other.add(cm.getColumn(5));
g_lang.add(g_other);
GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
header.addColumnGroup(g_name);
header.addColumnGroup(g_lang);

TableCellRenderer renderer = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
};

TableColumnModel model = table.getColumnModel();
for (int i=0;i<model.getColumnCount();i++) {
model.getColumn(i).setHeaderRenderer(renderer);
}
table.getTableHeader().setUI(new GroupableTableHeaderUI());
JScrollPane scroll = new JScrollPane( table );
getContentPane().add( scroll );
setSize( 400, 120 );
}

public static void main(String[] args) {
GroupableHeaderExample frame = new GroupableHeaderExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}

}

61.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: suma_sea
Posted on: 2005-07-20 09:30

实在佩服,竟然把JTABLE研究得如此透彻
解决了不少问题,谢谢

62.问一下如何将每一条纪录的字段从一行排列变为两行排列 [Re: kylin] Copy to clipboard
Posted by: jarsenal
Posted on: 2005-08-16 16:33

比如说有“名字”,“年龄”,“性别”,“学历”
一般是一行显示表头和每一条纪录,如:
“名字”,“年龄”,“性别”,“学历”
现在变为:
“名字”,“年龄”,
“性别”,“学历”

请问如何实现?

63.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: iris0903
Posted on: 2005-08-25 01:03

请问一下,为什么当我用liquid的look and feel时显示的表格是没有边框的呢?

64.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: 末代地主
Posted on: 2005-09-04 11:14

怎么我把第一页的打包程序拷下来却不能运行呢?运行提示说在枚举类型那里出现错误。
请问哪位大侠能给一段简单点的相关单元格合并的程序吗?多谢先!!

65.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: 末代地主
Posted on: 2005-09-08 21:48

怎么没有人回信息啊,求各位大侠帮帮忙!!多谢先!!

66.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: hdu119
Posted on: 2005-11-18 22:37

各位,小弟现请教一难题!如设计如下形状的表头有什么好的反案吗??


也就是实现表头有T型合并功能!!麻烦各位出点方案!!

T型表头.doc (35.0k)

67.JTable表中能进行单元格合并吗?? [Re: kylin] Copy to clipboard
Posted by: hdu119
Posted on: 2005-11-21 15:05

各位,小弟现请教一难题!如设计如下形状的表头有什么好的反案吗??

也就是实现表头有T型合并功能!!麻烦各位出点方案!!

68.JTable表中能进行单元格合并吗?? [Re: kylin] Copy to clipboard
Posted by: hdu119
Posted on: 2005-11-24 22:22

这里人气怎么这么不旺啊!!问了几天的问题都没有人来给点建议:(
无奈,硬着头皮自己解决了!!

69.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: yeskky
Posted on: 2005-12-28 16:29

看了这个帖子真是收获不少啊!
我有个问题。
我这儿的项目也是两行表头的,但是还要求两行表头还能交换位置。
具体是用菜单选择,哪个在上面,哪个在下面。
这个能实现吗?

70.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: AdamChen310
Posted on: 2006-02-18 11:53

为什么在 JDK1.5中老是不显示多行呢?大家

71.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: liuzhenke15
Posted on: 2006-03-26 13:02

JTable 的功能还是很强的
1.5在显示上有了一点改进

(缩略图,点击图片链接看原图)

72.Re:如何用JTable设置表头多行 [Re: kylin] Copy to clipboard
Posted by: zf00110011
Posted on: 2006-05-23 19:51

这个是用SWING实现的,请问斑竹,这样的表格在SWT中如何实现?小弟弄了好几天都没弄出来。。。。。。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923