Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - floater , 2004-10-18 11:14
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 Re:如何用JTable设置表头多行 [Re:kylin]
hyhoo7





发贴: 3
积分: 0
于 2005-06-16 09:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在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);
}

}


kavinwang edited on 2005-06-16 11:30


话题树型展开
人气 标题 作者 字数 发贴时间
160741 [精华] 如何用JTable设置表头多行 kylin 299 2004-10-18 10:25
139563 Re:如何用JTable设置表头多行 kylin 15 2004-10-18 10:40
138114 Re:如何用JTable设置表头多行 kavinwang 40 2004-10-19 22:40
137908 Re:如何用JTable设置表头多行 kylin 39 2004-10-20 10:29
137106 Re:如何用JTable设置表头多行 xcontinue 50 2004-12-22 11:13
136401 Re:如何用JTable设置表头多行 kavinwang 1900 2004-10-20 12:56
137438 Re:如何用JTable设置表头多行 kylin 97 2004-10-21 14:00
137428 Re:如何用JTable设置表头多行 kavinwang 126 2004-10-21 14:26
137289 Re:如何用JTable设置表头多行 kylin 39 2004-10-21 17:22
137346 Re:如何用JTable设置表头多行 kylin 36 2004-10-21 17:32
137140 Re:如何用JTable设置表头多行 kavinwang 21 2004-10-21 18:38
137356 Re:如何用JTable设置表头多行 kylin 52 2004-10-22 08:56
138886 Re:如何用JTable设置表头多行 kavinwang 100 2004-10-22 09:28
138112 Re:如何用JTable设置表头多行 kylin 9 2004-10-18 11:01
136682 Re:如何用JTable设置表头多行 xcontinue 27 2004-12-25 19:06
137176 Re:如何用JTable设置表头多行 kylin 140 2004-10-22 11:47
137181 Re:如何用JTable设置表头多行 kavinwang 61 2004-10-22 13:00
137171 Re:如何用JTable设置表头多行 kylin 71 2004-10-22 16:28
137134 Re:如何用JTable设置表头多行 kylin 41 2004-10-22 17:59
137340 Re:如何用JTable设置表头多行 kylin 58 2004-10-22 18:01
137095 Re:如何用JTable设置表头多行 kavinwang 68 2004-10-23 22:08
137041 Re:如何用JTable设置表头多行 kylin 65 2004-10-25 15:46
137004 Re:如何用JTable设置表头多行 kavinwang 7 2004-10-25 16:41
137715 Re:如何用JTable设置表头多行 kylin 585 2004-10-25 17:45
135572 Re:如何用JTable设置表头多行 kavinwang 689 2004-10-26 09:43
137181 Re:如何用JTable设置表头多行 floater 94 2004-10-18 11:14
136981 Re:如何用JTable设置表头多行 kylin 45 2004-10-26 14:02
137299 Re:如何用JTable设置表头多行 hujianso 71 2004-10-28 11:08
136872 Re:如何用JTable设置表头多行 kavinwang 24 2004-10-28 14:34
137590 Re:如何用JTable设置表头多行 kylin 159 2004-10-29 10:28
136672 Re:如何用JTable设置表头多行 javatool 33 2004-11-02 10:30
137049 Re:如何用JTable设置表头多行 xiaoxiaoxia 352 2004-12-15 09:20
136471 Re:如何用JTable设置表头多行 kylin 17 2004-12-22 11:40
136938 Re:如何用JTable设置表头多行 kylin 70 2004-12-22 13:54
136671 Re:如何用JTable设置表头多行 kylin 13 2004-12-22 14:02
136580 Re:如何用JTable设置表头多行 xcontinue 53 2004-12-25 19:08
136984 Re:如何用JTable设置表头多行 floater 19 2004-10-18 11:15
137313 Re:如何用JTable设置表头多行 xcontinue 57 2004-12-25 19:12
137516 Re:如何用JTable设置表头多行 xcontinue 70 2004-12-26 17:11
134971 Re:如何用JTable设置表头多行 billyzorro 23 2005-03-30 09:17
136507 Re:如何用JTable设置表头多行 xcontinue 11 2004-12-28 10:53
136245 Re:如何用JTable设置表头多行 kavinwang 72 2004-12-28 11:16
136330 Re:如何用JTable设置表头多行 ccvcd 65 2005-01-12 17:39
135512 Re:如何用JTable设置表头多行 javatool 47 2005-01-31 13:50
138037 借宝地提问tame.exmple.AnimatedIconHeaderExample windcao 178 2005-02-24 15:23
137602 欢迎大家参与tame的重新整理工作,积极讨论 windcao 60 2005-02-24 15:35
135887 Re:如何用JTable设置表头多行 ShiZhen 204 2005-02-28 19:34
135243 Re:如何用JTable设置表头多行 kavinwang 27 2005-03-01 08:44
139725 Re:如何用JTable设置表头多行 kylin 73 2004-10-18 15:22
135512 Re:如何用JTable设置表头多行 杰克逊 67 2005-03-02 11:46
135083 Re:如何用JTable设置表头多行 zhansy 52 2005-03-18 22:40
134947 Re:如何用JTable设置表头多行 seeler 8 2005-03-30 08:54
134080 Re:如何用JTable设置表头多行 ljy789654 34 2005-05-10 15:53
132884 Re:如何用JTable设置表头多行 mylzw 36 2005-05-14 19:35
133902 Re:如何用JTable设置表头多行 leigh 146 2005-06-08 15:33
132698 Re:如何用JTable设置表头多行 hyhoo7 3495 2005-06-16 09:43
133577 Re:如何用JTable设置表头多行 suma_sea 33 2005-07-20 09:30
133084 问一下如何将每一条纪录的字段从一行排列变为两行排列 jarsenal 105 2005-08-16 16:33
132377 Re:如何用JTable设置表头多行 iris0903 45 2005-08-25 01:03
135591 Re:如何用JTable设置表头多行 kavinwang 2419 2004-10-18 21:55
132151 Re:如何用JTable设置表头多行 末代地主 72 2005-09-04 11:14
132091 Re:如何用JTable设置表头多行 末代地主 25 2005-09-08 21:48
130531 Re:如何用JTable设置表头多行 hdu119 65 2005-11-18 22:37
132618 JTable表中能进行单元格合并吗?? hdu119 64 2005-11-21 15:05
131710 JTable表中能进行单元格合并吗?? hdu119 47 2005-11-24 22:22
129026 Re:如何用JTable设置表头多行 yeskky 86 2005-12-28 16:29
127706 Re:如何用JTable设置表头多行 AdamChen310 23 2006-02-18 11:53
127320 Re:如何用JTable设置表头多行 liuzhenke15 30 2006-03-26 13:02
130987 Re:如何用JTable设置表头多行 zf00110011 51 2006-05-23 19:51
137791 Re:如何用JTable设置表头多行 kylin 181 2004-10-19 09:38
138120 Re:如何用JTable设置表头多行 kavinwang 51 2004-10-19 13:20
137142 Re:如何用JTable设置表头多行 floater 277 2004-10-19 22:16

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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