java中如何实现表格的多表头显示
首先声明,这些内容都是借鉴来的,稍微改动了一下。
主要就是三个应用类ColumnGroup, GroupableTableHeader,GroupableTableHeaderU
和一个示例类GroupableHeaderExample
1、ColumnGroup类主要负责多表头的构建
import java.awt.Component;
import java.awt.Dimension;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
public class ColumnGroup {
protected TableCellRenderer renderer;
protected Vector v;
protected String text;
protected int margin = 0;
public ColumnGroup(String text) {
this(null, text);
}
public ColumnGroup(TableCellRenderer renderer, String text) {
if (renderer == null) {
this.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) {
补充:Jsp教程,Java技巧及代码