我建立一个单元格绘制器的类,然后设置给jtable,但并没有生效,请问这是怎么回事
public class DataWindow extends JTable
{
public DataWindow(Connection cnn,ResultSet rs,
String titleStr, String uneditColNameStr ,String unshowColNameStr)
{
super(new DataWindowTableModel(cnn,rs,titleStr,
uneditColNameStr,unshowColNameStr));
this.setRowHeight(50);
this.setRowHeight(0,1);
this.setDefaultRenderer(String.class,new DataWindowCellRender(35.0f));
}
public Object getCurrentValue()
{
return this.getValueAt(this.getSelectedRow(),this.getSelectedColumn());
}
}
class DataWindowCellRender implements TableCellRenderer
{
private float size;
public DataWindowCellRender(float size)
{
this.size=size;
}
public Component getTableCellRendererComponent
(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column)
{
JTextField text=new JTextField((String)value);
text.setFont(new Font(null,Font.BOLD,32));
text.setBackground(Color.red);
return text;
}
}
public class DataWindow extends JTable
{
public DataWindow(Connection cnn,ResultSet rs,
String titleStr, String uneditColNameStr ,String unshowColNameStr)
{
super(new DataWindowTableModel(cnn,rs,titleStr,
uneditColNameStr,unshowColNameStr));
this.setRowHeight(50);
this.setRowHeight(0,1);
this.setDefaultRenderer(String.class,new DataWindowCellRender(35.0f));
}
public Object getCurrentValue()
{
return this.getValueAt(this.getSelectedRow(),this.getSelectedColumn());
}
}
class DataWindowCellRender implements TableCellRenderer
{
private float size;
public DataWindowCellRender(float size)
{
this.size=size;
}
public Component getTableCellRendererComponent
(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column)
{
JTextField text=new JTextField((String)value);
text.setFont(new Font(null,Font.BOLD,32));
text.setBackground(Color.red);
return text;
}
}
mtable.getTableHeader().setFont(new Font("宋体", Font.BOLD, 16));
mtable.setFont(new Font("宋体", 0, 16));