如何为JTable行着色 [英] How to color JTable rows
本文介绍了如何为JTable行着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为JTable行着色(使用netbeans进行拖放编程)?
解决方案
我找到了解决方案,
< pre lang =java> urtablename.setDefaultRenderer(Object。 class , new DefaultTableCellRenderer()
{
public 组件getTableCellRendererComponent(JTable表,对象值,
boolean isSelected , boolean hasFocus, int 行, int 列)
{
final 组件c = super .getTableCellRendererComponent(table,value ,isSelected,hasFocus,row,column);
c.setBackground(row% 2 == 0 ?Color.lightGray:Color.WHI TE);
return c;
}
}
此代码让jtable有2种颜色(一行白色,一行灰色......)
How can i color JTable rows (in drag and drop programming using netbeans) ?
解决方案
I found the solution,
urtablename.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 == 0 ? Color.lightGray : Color.WHITE); return c; } }
this code let the jtable with 2 colours (one row white one row gray ... )
这篇关于如何为JTable行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文