我正在尝试调整 jtable 单元格内的滑块大小。但是在调整列标题的大小时,我确实传入了相关代码(第一列的方法 getTableCellRendererComponent),但没有任何反应(滑块没有调整大小??)。
下面是我的渲染器的代码:
public class NavigationDataModelRenderer extends JLabel implements TableCellRenderer {
private JSlider slider = null;
public NavigationDataModelRenderer()
{
super();
}
public NavigationDataModelRenderer(int tolerance)
{
super();
slider = new JSlider(tolerance * -3,tolerance *3);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(tolerance);
slider.setUI(new SpreadSliderUI(slider));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column)
{
Component comp = null;
if (table.getModel()!= null && table.getModel() instanceof NavigationDataModel)
{
NavigationDataModel model = (NavigationDataModel) table.getModel();
Object o = table.getModel().getValueAt(row, column);
this.setText(o.toString());
if (column == 1)
{//slider
if (model.getList() != null && model.getList().get(0)!= null && model.getList().get(row) != null)
{
slider.setValue((Integer)o);
}
comp = slider;
slider.setSize(table.getCellRect(row, column, false).getSize());
}
else if (column == 2)
{
if (((Integer)o) == Integer.MAX_VALUE)
{
this.setText("Invalid");
}
}
else
{
comp = this;
}
}
return comp;
}
}
谢谢你的帮助。