Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Main {
    public static void main(String[] args) {
        String[][] data = { { "Data", "Data" } };
        String[] col = { "Col", "Col" };
        final DefaultTableModel model = new DefaultTableModel(data, col);
        JTable table = new JTable(model);
        JButton addRow = new JButton("Add Empty Row");
        addRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                model.addRow(new Object[] {});
            }
        });
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JScrollPane(table));
        panel.add(addRow, BorderLayout.SOUTH);
        JOptionPane.showMessageDialog(null, panel);
    }
}