Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.tree.TreeCellEditor;

public class Main {

    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);

        JComboBox comboBox = new JComboBox(new String[] { "A", "B", "C" });
        TreeCellEditor editor = new DefaultCellEditor(comboBox);

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

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

}

class MyDefaultCellEditor extends DefaultCellEditor {

    public MyDefaultCellEditor(JComboBox comboBox) {
        super(comboBox);
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
            int column) {

        return super.getTableCellEditorComponent(table, value, isSelected, row, column);
    }
}