Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Main {

    public static void main(String args[]) {
        JFrame f = new JFrame();
        f.setSize(new Dimension(300, 300));
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(new FlowLayout());
        JLabel label = new JLabel("Update");
        String[] data = { "one", "two", "three", "four" };
        JList<String> dataList = new JList<>(data);

        dataList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent arg0) {
                if (!arg0.getValueIsAdjusting()) {
                    label.setText(dataList.getSelectedValue().toString());
                }
            }
        });
        f.add(new JScrollPane(dataList));
        f.add(label);

        f.setVisible(true);
    }

}