Terai Atsuhiro 2023-11-16 (木) 14:54:55

http://terai.xrea.jp/swing/celleditorborder/screenshot.png

JTextField tf = new JTextField();
tf.setBorder(BorderFactory.createLineBorder(Color.red, 2));
table.setDefaultEditor(Object.class, new DefaultCellEditor(tf));

JTextField tf2 = new JTextField();
tf2.setBorder(BorderFactory.createLineBorder(Color.green, 2));
tf2.setHorizontalAlignment(JTextField.RIGHT);
table.setDefaultEditor(Integer.class, new DefaultCellEditor(tf2));
table = new JTable(sorter) {
  public Class getColumnClass(int column) {
    if(column==0) {
      return Integer.class;
    }
    return Object.class;
  }
};
TestRenderer tr = new TestRenderer();
table.setDefaultRenderer(Object.class,  tr);
table.setDefaultRenderer(Integer.class, tr);