package fest;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

@SuppressWarnings("serial")
public class FrameWithScroll extends JFrame {
	private JPanel panelTop;
	private JPanel panelBottom;
	private JButton button;
	private JPanel emptyPanel;

	public FrameWithScroll() {
		super("Test Scroll");
		initComponents();
		initialize();
	}

	private void initComponents() {
		panelTop = new JPanel();
		
		emptyPanel = new JPanel();
		emptyPanel.setPreferredSize(new Dimension(300, 600));

		button = new JButton("Click me");
		button.setName("button");
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("Clicked Button");
			}
		});
		
		panelBottom = new JPanel();
		panelBottom.setPreferredSize(new Dimension(750, 700));
	}

	private void initialize() {
		this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));

		GridBagLayout gridBagLayout = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		
		panelTop.setLayout(gridBagLayout);
		
		c.gridx = 0;
		c.gridy = 0;
		panelTop.add(emptyPanel, c);

		c.gridy++;
		panelTop.add(button, c);
		
		this.add(new JScrollPane(panelTop));

		this.add(panelBottom);

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
}

