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

package com.elex_project.examples.layouts;

import javax.swing.*;

public class GroupLayoutExample extends JPanel {

	GroupLayoutExample() {
		super();
		final GroupLayout layout = new GroupLayout(this);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		setLayout(layout);

		final JButton button1 = new JButton("Button 1");
		final JButton button2 = new JButton("Button 2");
		final JButton button3 = new JButton("Button 3");
		final JButton button4 = new JButton("Button 4");
		final JButton button5 = new JButton("Button 5");

		layout.setHorizontalGroup(layout.createSequentialGroup()
				.addComponent(button1)
				.addComponent(button2)
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(button3)
						.addComponent(button4)
						.addComponent(button5))
		);
		layout.setVerticalGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(button1)
						.addComponent(button2)
						.addComponent(button3))
				.addComponent(button4)
				.addComponent(button5));

	}

	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 GroupLayoutExample());

		// 이벤트 디스패치 스레드에서 프레임을 표시한다.
		SwingUtilities.invokeLater(() -> {
			jFrame.setVisible(true);
		});

	}
}
