运行时表头无法显示且提示:UIDefaults.getUI() failed: no ComponentUI class for: ...
java.lang.Error ...
请问:参数C的作用,如何修改这段代码?谢谢!
(注:代码来自http://www.54bk.com/?uid-776-action-viewspace-itemid-30520)
public static ComponentUI createUI(JComponent c) {
return new GroupableTableHeaderUI();
}
public void paint(Graphics g, JComponent c) { //提示:未使用参数C
TableColumnModel cm = header.getColumnModel();
if (cm.getColumnCount() > 0) {
Rectangle clip = g.getClipBounds();
Point left = clip.getLocation();
Point right = new Point(clip.x + clip.width - 1, clip.y);
int cMin = header.columnAtPoint(left);
int cMax = header.columnAtPoint(right);
if (cMax == -1) {
cMax = cm.getColumnCount() - 1;
}
int columnWidth;
Rectangle cellRect = header.getHeaderRect(cMin);
Set done = new HashSet();
for (int column = cMin; column <= cMax; column++) {
TableColumn aColumn = cm.getColumn(column);
columnWidth = aColumn.getWidth();
cellRect.width = columnWidth;
paintCell(done, g, cellRect, column);
cellRect.x += columnWidth;
}
rendererPane.removeAll();
}
}
2 个解决方案
#1
实现JComponent的类,譬如JPanel
#2
怎么个实现法?我也遇到了这个问题。
#1
实现JComponent的类,譬如JPanel
#2
怎么个实现法?我也遇到了这个问题。