Making use of both cell renderer and editor but still scrollbar isn't working please suggest anything that make it work scrollbar is not moving at all
class MultiRowCell extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
private JScrollPane scrollPane;
private JTextArea textArea;
public MultiRowCell() {
textArea = new JTextArea();
textArea.setEditable(true);
scrollPane = new JScrollPane(textArea);
}
@Override
public boolean isCellEditable(EventObject e) {
System.out.println(e);
return true;
}
@Override
public Object getCellEditorValue() {
return textArea.getText();
}
protected void setCellValue(Object value) {
if (value == null) {
textArea.setText(null);
} else {
textArea.setText(value.toString());
}
textArea.setCaretPosition(0);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
setCellValue(value);
return scrollPane;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
setCellValue(value);
return scrollPane;
}
}
//TextTableCellRenderer tr=new TextTableCellRenderer();
//table.getColumnModel().getColumn(1).setCellEditor(tr);
MultiRowCell re=new MultiRowCell();
table.getColumnModel().getColumn(1).setCellRenderer(re);
table.getColumnModel().getColumn(1).setCellEditor(re);
//table.getColumnModel().getColumn(1).setCellRenderer(r);
//table.getColumnModel().getColumn(1).setCellEditor(e);
//table.getColumnModel().getColumn(2).setCellRenderer(r);
//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
panel.setLayout(new BorderLayout());
panel.add(table, BorderLayout.CENTER);
panel.add(table.getTableHeader(), BorderLayout.NORTH);
return panel;
Conceptually you will need a cell renderer AND cell editor in order to make it work, for example...
Note, I read the entire Rouge One script from a local resource for the example, you'll need to supply your own text
Caveat: This example will require you to click the cell to switch to editing mode as the mouse wheel events are been used by the scroll pane that wraps the
JTable