Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

public class Main {

    public static void main(String args[]) {
        JFrame frame = new JFrame();
        frame.setSize(450, 250);

        JTable table = new JTable(5, 5);

        TableColumn testColumn = table.getColumnModel().getColumn(0);

        JComboBox<String> comboBox = new JComboBox<>();
        comboBox.addItem("This");
        comboBox.addItem("is");
        comboBox.addItem("a");
        comboBox.addItem("Sample program");
        testColumn.setCellEditor(new DefaultCellEditor(comboBox));

        frame.add(table);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}