import java.awt.BorderLayout; import java.util.ArrayList; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class MainFrame extends JFrame{ DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(); JScrollPane pane = new JScrollPane(); public MainFrame() { ArrayList employeeList = new ArrayList<>(); employeeList.add(new Employee(1, "Erős István", "Szeged", 395.0)); employeeList.add(new Employee(2, "Csontos Ferenc", "Szolnok", 392.3)); Object[] cols = {"#", "Név", "Település", "Fizetés"}; this.model.setColumnIdentifiers(cols); for (Employee emp : employeeList) { Vector row = new Vector<>(); row.add(emp.id); row.add(emp.name); row.add(emp.city); row.add(emp.salary); model.addRow(row); } this.table.setModel(model); this.pane.setViewportView(table); this.table.getColumnModel().getColumn(0).setPreferredWidth(5); this.setLayout(new BorderLayout()); this.add(pane, BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(400, 300); this.setVisible(true); } }