Skip to main content

JXTreeTable CellEditor for Nodeclass

3 replies [Last post]
alcabohni
Offline
Joined: 2012-11-19
Points: 0

Hi All

I try to build an Editor Tree where i have a Column with Identifiers or Descriptions and a Second Column with the Values.

Now when all Node are Editor for Text i have no problem. but i have now to add an Node with a Combobox how i can add this Combobox in that second Cell?

this is the code for the Edit TreeNode:

import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
public abstract class EditTreeNode extends AbstractMutableTreeTableNode {

    private String Bezeichnung;

    public EditTreeNode(String Bezeichnung) {
        super();
        this.Bezeichnung = Bezeichnung;
    }

    @Override
    public boolean isEditable(int column) {
        return column == 1;
    }

    @Override
    public void setValueAt(Object aValue, int column) {
        if (column == 1) {
            setValue(aValue);
        } else {
            super.setValueAt(aValue, column);
        }
    }

    @Override
    public Object getValueAt(int column) {
        switch (column) {
            case 0:
                return Bezeichnung;
            case 1:
                return getValue();
        }
        return "";
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    public abstract Object getValue();

    public abstract void setValue(Object aValue);
}

and here i add this Node (Text Editor) to the Tree via an other DefaultMutableTreeTableNode:

        Infos = new DefaultMutableTreeTableNode(smartDiagEditorLangfile.getString("FEHLERINFOS"));
        Kurztext = new EditTreeNode(smartDiagEditorLangfile.getString("KURZTEXT")) {
            @Override
            public Object getValue() {
                return getFehler().getKurztext();
            }

            @Override
            public void setValue(Object aValue) {
                getFehler().setKurztext((String) aValue);
                DaoProvider.getInstance().getFehlerDao().updateItem(getFehler());
            }
        };
        Beschreibung = new EditTreeNode(smartDiagEditorLangfile.getString("BESCHREIBUNG")) {
            @Override
            public Object getValue() {
                return getFehler().getBeschreibung();
            }

            @Override
            public void setValue(Object aValue) {
                getFehler().setBeschreibung((String) aValue);
                DaoProvider.getInstance().getFehlerDao().updateItem(getFehler());
            }
        };
        Infos.add(Kurztext);
        Infos.add(Beschreibung);

any help is welcome, be blessed André

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

Column 2 is a normal table column, add a combo box editor as you would with a standard table.

Karl

alcabohni
Offline
Joined: 2012-11-19
Points: 0

Hello Karl

Thanks for you Answer.

But i think you have misunderstud me. not all Editors in the Second Column are ComboBox there also Nodes that uses Textfields. an there i have the Problem. To add more than one typ of editor in the same Column.

be blessed André

kschaefe
Offline
Joined: 2006-06-08
Points: 0

You would still need to do the same thing as you would with a JTable. You will have to have some type of compound editor that delegates to the correct one (text field or combo box), based on some criteria, such as value contents.

Karl