Test.java Source code

Java tutorial

Introduction

Here is the source code for Test.java

Source

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class Test extends JFrame {

    public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel1 = new JPanel(new GridLayout(1, 5));
        for (int i = 0; i < 5; i++) {
            panel1.add(new JLabel("Left " + i));
        }
        panel1.setPreferredSize(new Dimension(250, 50));

        JPanel panel2 = new JPanel(new GridLayout(1, 5));
        for (int i = 0; i < 5; i++) {
            panel2.add(new JLabel("Right " + i));
        }
        panel2.setPreferredSize(new Dimension(250, 50));

        final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2);
        split.setContinuousLayout(true);
        getContentPane().add(split, BorderLayout.CENTER);
        pack();
        setSize(500, 100);
    }

    public static void main(String[] args) {
        new Test().setVisible(true);
    }
}