Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTreeTable - How to make CellEditable after only a certain number of clicks

843806Dec 2 2008 — edited Dec 2 2008
Hello,

I have a JtreeTable with three columns (0,1,2). Column 0 and 2 are not editable, whereas the middle column (1) can be edited (setValueAt) by the user.

My problem is that I want any cell on column 1 to be editable only after i have clicked "two times" on the respective cell.

At the moment, the cells on column 1 are editable with only one click and what is more annoying is that there is no text cursor displayed to indicate that the cell has actually become editable.

I have tried *"hoodNumberEditor.setClickCountToStart(2);"* (pls see below)
to solve the problem but it doesnt work.

Pls help.

Thanks,
Berkan
package jxtreetable;

import jxtreetablemodel.DataModel;
import java.awt.BorderLayout;
import java.awt.Cursor;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableCellRenderer;
import org.jdesktop.swingx.JXTable.NumberEditor;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
import org.jdesktop.swingx.renderer.StringValue;


public class HoodInputTable extends JPanel {

    DataModel model;
    JXTreeTable table;
    NumberEditor hoodNumberEditor;
    DefaultTableCellRenderer hoodTableCellRenderer;
    private DefaultTableRenderer hoodTableRenderer;
    public DataModel getModel() {
        return model;
    }

    public void setModel(DataModel model) {
        this.model = model;
        table.setTreeTableModel(model);
        table.setSelectionMode(0);
        table.getColumn(0).setMinWidth(200);

        hoodNumberEditor = new NumberEditor();
        hoodNumberEditor.setClickCountToStart(2);
        table.getColumn(1).setCellEditor(hoodNumberEditor);
        table.getColumn(1).setCellRenderer(
                new DefaultTableRenderer(new SimpleStringValue(), DefaultTableCellRenderer.RIGHT));
        table.getColumn(2).setCellRenderer(
                new DefaultTableRenderer(new HtmlizeStringValue(), DefaultTableCellRenderer.LEFT));
        table.expandAll();
    }

    static class SimpleStringValue implements StringValue {

        public String getString(Object obj) {
            return obj == null ? "" : obj.toString();
        }
    }

    static class HtmlizeStringValue implements StringValue {

        public String getString(Object obj) {
            return obj == null ? "" : "<html>" + obj.toString() + "</html>";
        }
    }

    public HoodInputTable(DataModel model) {

        super(new BorderLayout());
        this.model = model;

        table = new JXTreeTable();
        setModel(model);

        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane, BorderLayout.CENTER);
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 30 2008
Added on Dec 2 2008
1 comment
122 views