Adding a JScrollPane Component to a JTable Column

I am trying to add scrolling capabilities to a specific column in JTable. I have implemented the custom component TableCellRenderer, and I see the scroll bar inside the table in order, but I cannot scroll it. I also tried to implement TableCellEditor and had no luck.

    public Component getTableCellEditorComponent(JTable arg0, Object arg1,
        boolean arg2, int arg3, int arg4) {
    return scrollPane;
}

Does anyone have any ideas how to make these cells that contain scrollPane scroll?

+3
source share
3 answers

With TableCellRenderer, it is not possible to add any scroll behavior since it does not accept any events and only draws the component. You can, however, accomplish this using a custom TableCellEditor with getTableCellEditor:

public Component getTableCellEditorComponent(JTable table, Object value, boolean   isSelected, int row, int column) {
    JTextArea area = new JTextArea();
    area.setLineWrap(true);
    area.setText((String) value);

    JScrollPane pane = new JScrollPane(area);

    return pane;
}

, CellEditor. , isCellEditable :

public boolean isCellEditable(EventObject anEvent) {
    return true;
}

, , -. , . -, .

+5

A Renderer . , TableCellEditor.

+2

.

+2

All Articles