TreeEditJCheckBox.java Source code

Java tutorial

Introduction

Here is the source code for TreeEditJCheckBox.java

Source

import java.awt.BorderLayout;
import java.util.Properties;

import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.TreeCellEditor;

public class TreeEditJCheckBox {
    public static void main(String args[]) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Properties props = System.getProperties();
        JTree tree = new JTree(props);

        JCheckBox checkBox = new JCheckBox("To be or not to be");
        TreeCellEditor editor = new DefaultCellEditor(checkBox);

        tree.setEditable(true);
        tree.setCellEditor(editor);

        JScrollPane scrollPane = new JScrollPane(tree);
        frame.add(scrollPane, BorderLayout.CENTER);
        frame.setSize(300, 150);
        frame.setVisible(true);
    }
}