I have a sample code that we use to dynamic row numbers in Java
Swing
Table i.e JTable
. I new to JavaFX
and would like to the same in JavaFX
. Is there is any way to set automatic row numbers in JavaFX
Table
class LineNumberTable extends JTable {
private JTable mainTable;
public LineNumberTable(JTable table) {
super();
mainTable = table;
setAutoCreateColumnsFromModel(false);
setModel(mainTable.getModel());
setAutoscrolls(false);
addColumn(new TableColumn());
getColumnModel().getColumn(0).setCellRenderer(mainTable.getTableHeader().getDefaultRenderer());
getColumnModel().getColumn(0).setPreferredWidth(40);
setPreferredScrollableViewportSize(getPreferredSize());
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == uneditableColumn) {
return false;
}
return bEdit;
}
@Override
public Object getValueAt(int row, int column) {
return Integer.valueOf(row + 1);
}
@Override
public int getRowHeight(int row) {
return mainTable.getRowHeight();
}
}