⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jlistdemo.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

/**
 * Demonstrates the component {@link JList}. This class extends
 * class {@link @JPanel}.
 *
 * @author author name
 * @version 1.0.0
 */
public class JListDemo extends JPanel {

    private JList listOne;
    private JList listTwo;

    private static final String fruitNames[] =
        {"Orange", "Pear", "Apple", "Pineapple", "Peach",
         "Grapefruit", "Lemon", "Grape"};

    /**
     * Creates a window.
     *
     * @param args  not used.
     */
    public static void main(String[] args) {

        JFrame frame = new JFrame("JListDemo");

        frame.setContentPane(new JListDemo());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();    // Adjust the size of the window
        frame.setVisible(true);
    }

    /**
     * Creates two {@link JList} components.
     */
    public JListDemo() {

        setBackground(Color.white);

        // Create the components
        listOne = new JList(fruitNames);
        listTwo = new JList(fruitNames);

        // Customize the list properties
        listOne.setVisibleRowCount(5);
        listTwo.setVisibleRowCount(5);
        listOne.setSelectionMode(
            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        listTwo.setSelectionMode(
            ListSelectionModel.SINGLE_SELECTION);
        listOne.setFixedCellHeight(15);
        listOne.setFixedCellWidth(100);
        listTwo.setFixedCellHeight(15);
        listTwo.setFixedCellWidth(100);

        // Change the colors of the lists
        listOne.setBackground(new Color(0, 0, 150));
        listTwo.setBackground(new Color(0, 150, 0));
        listOne.setForeground(Color.white);
        listTwo.setForeground(Color.white);

        // Add lists to the scrollbar containers
        add(new JScrollPane(listOne,
                             JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
        add(new JScrollPane(listTwo,
                             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                             JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -