Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Dimension;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

public class Main {

    public static void main(String[] args) {
        DefaultListModel<String> model = new DefaultListModel<>();
        JList<String> sList = new JList<>(model);
        for (int i = 0; i < 100; i++) {
            model.addElement("String " + i);
        }

        sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        sList.setVisibleRowCount(-1);
        sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);

        JFrame frame = new JFrame("Foo001");
        frame.getContentPane().add(new JScrollPane(sList));
        frame.getContentPane().setPreferredSize(new Dimension(400, 300));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}