/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package com.elex_project.examples.components.table;

import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.swing.*;
import java.awt.*;

public class TableExample extends JPanel {

	public TableExample() {
		super(new BorderLayout());

		final Object[] header = {"이름", "나이", "주소"};
		final Object[][] data = {
				new Object[]{"Charlie", 13, "서울"},
				new Object[]{"Steve", 34, "대전"},
				new Object[]{"Jane", 23, "대구"},
				new Object[]{"Jack", 48, "부산"},
		};

		final JTable table = new JTable(data, header);
		table.setFillsViewportHeight(true);
		table.setRowSelectionAllowed(true);
		table.getColumnModel().getColumn(0).setPreferredWidth(80);
		table.getColumnModel().getColumn(1).setPreferredWidth(40);
		table.getColumnModel().getColumn(2).setPreferredWidth(180);


		add(new JScrollPane(table), BorderLayout.CENTER);
	}

	public static void main(String... args) {

		final JFrame jFrame = new JFrame();
		jFrame.setTitle("Example");
		jFrame.setSize(800, 600);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setContentPane(new TableExample());

		SwingUtilities.invokeLater(() -> {
			jFrame.setVisible(true);
		});

	}


}
