Babu R
Babu R

Reputation: 1035

JTree click event not working

Hi I am new to the Jtree component.

I am adding nodes dynamically according to button click events. The nodes are added successfully when I click a button, but after adding a panel on node click event, the node functionality (ie, when clicking on node buttons that are visible) stops not working.

enter image description here

This is my code:

@Override
public void valueChanged(TreeSelectionEvent event) {
    (tree.getLastSelectedPathComponent().toString().startsWith("Channel")) {
            //if i click Channel node the device button is not visible
            //block button have to invisible
            //treePanel contains jtree
            treePanel.revalidate();
            treePanel.repaint();
            modbusButton.setEnabled(false);
            channelButton.setEnabled(false);
            blockButton.setEnabled(false);
            deviceButton.setEnabled(true);

            modbus2 mcon = null;
            try {
                mcon = new modbus2();
            } catch (SQLException ex) {
                Logger.getLogger(ModBusTree.class.getName()).log(Level.SEVERE,null,ex);
            }



            ModbusMainPanel.rightPanel.removeAll();
            ModbusMainPanel.rightPanel.add(mcon.p2);
            ModbusMainPanel.rightPanel.revalidate();
            ModbusMainPanel.rightPanel.repaint();
        }
}

Upvotes: 1

Views: 989

Answers (1)

trashgod
trashgod

Reputation: 205875

You may get some insight from the tutorial section How to Use Trees: Dynamically Changing a Tree, which cites DynamicTreeDemo, a compete example similar to what you're doing.

DynamicTreeDemo

Upvotes: 1

Related Questions