2 个解决方案
#1
默认是左对齐吧?
#2
public class TbCellRender extends DefaultTableCellRenderer {
public TbCellRender(String orient,double down) {
if(orient==null||orient.trim().equals(""))
orient = "left";
this.down = down;
orient = orient.toLowerCase().trim();
char align = orient.charAt(0);
switch (align) {
case 'r':
setHorizontalAlignment(JLabel.RIGHT);
break;
case 'l':
setHorizontalAlignment(JLabel.LEFT);
break;
case 'c':
setHorizontalAlignment(JLabel.CENTER);
break;
default:
setHorizontalAlignment(JLabel.LEFT);
break;
}
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component comp = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
return comp;
}
public TbCellRender(String orient,double down) {
if(orient==null||orient.trim().equals(""))
orient = "left";
this.down = down;
orient = orient.toLowerCase().trim();
char align = orient.charAt(0);
switch (align) {
case 'r':
setHorizontalAlignment(JLabel.RIGHT);
break;
case 'l':
setHorizontalAlignment(JLabel.LEFT);
break;
case 'c':
setHorizontalAlignment(JLabel.CENTER);
break;
default:
setHorizontalAlignment(JLabel.LEFT);
break;
}
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component comp = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
return comp;
}
#1
默认是左对齐吧?
#2
public class TbCellRender extends DefaultTableCellRenderer {
public TbCellRender(String orient,double down) {
if(orient==null||orient.trim().equals(""))
orient = "left";
this.down = down;
orient = orient.toLowerCase().trim();
char align = orient.charAt(0);
switch (align) {
case 'r':
setHorizontalAlignment(JLabel.RIGHT);
break;
case 'l':
setHorizontalAlignment(JLabel.LEFT);
break;
case 'c':
setHorizontalAlignment(JLabel.CENTER);
break;
default:
setHorizontalAlignment(JLabel.LEFT);
break;
}
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component comp = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
return comp;
}
public TbCellRender(String orient,double down) {
if(orient==null||orient.trim().equals(""))
orient = "left";
this.down = down;
orient = orient.toLowerCase().trim();
char align = orient.charAt(0);
switch (align) {
case 'r':
setHorizontalAlignment(JLabel.RIGHT);
break;
case 'l':
setHorizontalAlignment(JLabel.LEFT);
break;
case 'c':
setHorizontalAlignment(JLabel.CENTER);
break;
default:
setHorizontalAlignment(JLabel.LEFT);
break;
}
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component comp = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
return comp;
}