Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class Main {

    public static void main(String[] args) {
        JPanel ui = new JPanel(new BorderLayout(1, 1));
        JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT);
        jtp.addTab("Apple", new JLabel("Apple"));
        jtp.addTab("Banana", new JLabel("Banana"));
        jtp.addTab("Cherries", new JLabel("Cherries"));
        jtp.addTab("Grapes", new JLabel("Grapes"));
        ui.add(jtp, BorderLayout.CENTER);
        jtp.setPreferredSize(new Dimension(200, 200));
        jtp.addChangeListener(e -> {
            if (e.getSource() instanceof JTabbedPane) {
                JTabbedPane pane = (JTabbedPane) e.getSource();
                System.out.println("Selected paneNo : " + pane.getSelectedIndex());
            }
        });
    }
}