import javax.swing.*;
import java.awt.*;
public class MainWindow extends JFrame {
public MainWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(MainWindow::new);
}
}
String[][] data = {
{"John", "Doe", "27"},
{"Alice", "Smith", "31"},
{"Tom", "Jones", "45"}
};
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
DefaultCellEditor cellEditor = new DefaultCellEditor(new JTextField());
table.setDefaultEditor(Object.class, cellEditor);
JPanel panel = new JPanel();
panel.add(button);
add(panel, BorderLayout.SOUTH);
button.addActionListener(e -> {
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
System.out.println(table.getValueAt(row, col));
});