是否有使用的目的:爲什麼我會在這個例子中使用JScrollPane?
附加(新JScrollPane的(名單))代替加(名單)在下面的代碼?
public class Gui extends JFrame {
private JList list;
private static String[] colorNames = {"black", "blue", "red", "white"};
private static Color[] colors = {Color.BLACK, Color.BLUE, Color.RED, Color.WHITE};
Gui() {
list = new JList(colorNames);
list.setVisibleRowCount(colorNames.length);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
**add(new JScrollPane(list))**;
}
}