我正在关注我发现的一些代码,(是的,我理解它是如何工作的)它来自这里:Code Link
如果单元格值设置为"黄色",我正在尝试设置单元格前景色
这是我的代码:
public class Board extends JPanel{
private static final long serialVersionUID = 1L;
int boardHeight = 20;
int boardWidth = 10;
JTable table;
public Board() {
table = new JTable(this.boardHeight, this.boardWidth);
table.setDefaultRenderer(String.class, new BoardTableCellRenderer());
table.setFocusable(false);
table.setShowGrid(false);
table.setRowMargin(0);
table.setIntercellSpacing(new Dimension(0,0));
table.setRowSelectionAllowed(false);
table.setVisible(true);
this.add(table);
this.setPreferredSize(new Dimension(table.getPreferredSize().width, (table.getPreferredSize().height + 85)));
}
public void paint(Graphics g) {
table.setRowHeight(20);
for (int x = 0; x < this.table.getColumnCount(); ++x) {
TableColumn col = this.table.getColumnModel().getColumn(x);
col.setPreferredWidth(20);
}
}
}
Run Code Online (Sandbox Code Playgroud)
还有Cell Renderer
public class …Run Code Online (Sandbox Code Playgroud) 我想在JTable的列中添加正确的cell-padding,我该怎么办?
我尝试在线搜索,但似乎无法找到明确的答案.
我希望有一个人可以帮助我.
此致,乍得