设置一个JTable中某些单元格的背景色
来源:互联网 发布:ci框架怎么连接数据库 编辑:程序博客网 时间:2024/04/30 00:42
Object [][] data={
{null, null, null, null,null,null,1},
{2, 3, 4, 5, 6, 7, 8},
{9, 10, 11, 12, 13, 14, 15},
{16, 17, 18, 19, 20, 21, 22},
{23, 24, 25, 26, 27, 28, 29},
{30, 31, null, null, null, null,null}
};
String [] head={
"日", "一", "二", "三","四","五","六"
};
JTable jTable1=new JTable(data,head);
jTable1.setRowHeight(40);
jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
JScrollPane jScrollPane1=new JScrollPane();
jTable1.setCellSelectionEnabled(true);
jTable1.setFont(new Font("SimSun", 0, 20));
jTable1.getTableHeader().setFont(new Font("SimSun",0, 20));
jTable1.getTableHeader().setReorderingAllowed(false);
jTable1.getTableHeader().setResizingAllowed(false);
jTable1.setEnabled(false);
TableColumn column=null;
for(int i=0;i<7;i++){
column=jTable1.getColumnModel().getColumn(i);
column.setPreferredWidth(60);
}
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
if((column == 0&&row!=3)||column == 6||(column == 3&&row==3))
setBackground(new java.awt.Color(255, 255, 0));
else
setBackground(new Color(255,255,255));
return super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}
};
for(int i=0;i<7;i++){
jTable1.getColumn(head[i]).setCellRenderer(tcr);
}
jScrollPane1.setViewportView(jTable1);
{null, null, null, null,null,null,1},
{2, 3, 4, 5, 6, 7, 8},
{9, 10, 11, 12, 13, 14, 15},
{16, 17, 18, 19, 20, 21, 22},
{23, 24, 25, 26, 27, 28, 29},
{30, 31, null, null, null, null,null}
};
String [] head={
"日", "一", "二", "三","四","五","六"
};
JTable jTable1=new JTable(data,head);
jTable1.setRowHeight(40);
jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
JScrollPane jScrollPane1=new JScrollPane();
jTable1.setCellSelectionEnabled(true);
jTable1.setFont(new Font("SimSun", 0, 20));
jTable1.getTableHeader().setFont(new Font("SimSun",0, 20));
jTable1.getTableHeader().setReorderingAllowed(false);
jTable1.getTableHeader().setResizingAllowed(false);
jTable1.setEnabled(false);
TableColumn column=null;
for(int i=0;i<7;i++){
column=jTable1.getColumnModel().getColumn(i);
column.setPreferredWidth(60);
}
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
if((column == 0&&row!=3)||column == 6||(column == 3&&row==3))
setBackground(new java.awt.Color(255, 255, 0));
else
setBackground(new Color(255,255,255));
return super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}
};
for(int i=0;i<7;i++){
jTable1.getColumn(head[i]).setCellRenderer(tcr);
}
jScrollPane1.setViewportView(jTable1);
0 0
- 设置一个JTable中某些单元格的背景色
- 设置一个JTable中某些单元格的背景色
- java swing jtable 给指定的(一个或多个)单元格设置背景色
- JTable中CheckBox单元格背景色渲染
- JTabel 背景设置半透明 与某些区域的单元格设置背景色
- 设置单元格背景色
- POI中设置单元格背景色
- JTable设置表头背景色
- fullCalendar设置单元格背景色
- POI 设置单元格背景色
- 一个牛人写的“设置jtable单元格颜色,以及jtable中实现复选框”的程序,备忘
- Excel2010关于设置单元格颜色和背景色的bug
- DevExpress GridControl 设置单元格 某一行的背景色
- 比较单元格的值并设置背景色
- DevExpress GridControl 设置单元格 某一行的背景色
- jTable 中单元格的颜色设置
- Swing之JTable篇设置表格选中行的前景色和背景色
- [jtable]设置复选框前景色与背景色
- java 数字转换成字符串
- Delphi实现类的持久化保存(DFM格式)
- java中判断目录是否存在
- chicken---TED
- 带有排序和过滤功能的 JTable((JDK 6.0新功能))
- 设置一个JTable中某些单元格的背景色
- bz1968 1968: [Ahoi2005]COMMON 约数研究
- android手势滑动处理
- SQLite Tutorial 5 : How to Import CSV or Excel file into SQLite database
- java类加载
- 创建Docker基本的debian镜像
- Java的事件处理机制
- Visitor(访问者)设计模式
- JFreeChart用法