⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctable.java

📁 合并jtable中单元格的例子,简明扼要 很值得参考学习
💻 JAVA
字号:
package com.neuri.ctable;

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;

public class CTable extends JTable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public CMap map;

	public CTable(CMap cmp, TableModel tbl) {
		super(tbl);
		map = cmp;
		setUI(new CTUI());
	}

	public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
		// required because getCellRect is used in JTable constructor
		if (map == null)
			return super.getCellRect(row, column, includeSpacing);
		// add widths of all spanned logical cells
		int sk = map.visibleCell(row, column);
		Rectangle r1 = super.getCellRect(row, sk, includeSpacing);
		if (map.span(row, sk) != 1)
			for (int i = 1; i < map.span(row, sk); i++) {
				r1.width += getColumnModel().getColumn(sk + i).getWidth();
			}
		return r1;
	}

	public int columnAtPoint(Point p) {
		int x = super.columnAtPoint(p);
		// -1 is returned by columnAtPoint if the point is not in the table
		if (x < 0)
			return x;
		int y = super.rowAtPoint(p);
		return map.visibleCell(y, x);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -