关于居中显示,重写这个方法就行了。 public Component getTableCellRendererComponent(
JTable table,Object value,boolean isSelected,
boolean hasFocus,int row,int col){
this.setText(value.toString());
setFont(new Font("SansSerif",0,12));
setHorizontalAlignment(SwingConstants.CENTER);//在这里
if(isSelected){
super.setBackground(table.getSelectionBackground());
this.setForeground(Color.red);
}else{
this.setBackground(Color.orange);
this.setForeground(Color.red);
}
if (hasFocus) {
setBorder( new LineBorder(new Color(0,200,0),1) );
}else{
setBorder(new EmptyBorder(1, 1, 1, 1));
}
if(table.getModel().isCellEditable(row,col)){
this.setBackground(Color.white);
this.setForeground(Color.black);
}
return this;
}
JTable table,Object value,boolean isSelected,
boolean hasFocus,int row,int col){
this.setText(value.toString());
setFont(new Font("SansSerif",0,12));
setHorizontalAlignment(SwingConstants.CENTER);//在这里
if(isSelected){
super.setBackground(table.getSelectionBackground());
this.setForeground(Color.red);
}else{
this.setBackground(Color.orange);
this.setForeground(Color.red);
}
if (hasFocus) {
setBorder( new LineBorder(new Color(0,200,0),1) );
}else{
setBorder(new EmptyBorder(1, 1, 1, 1));
}
if(table.getModel().isCellEditable(row,col)){
this.setBackground(Color.white);
this.setForeground(Color.black);
}
return this;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货