June 2017
Beginner
1296 pages
69h 23m
English
JList.
1 // Fig. 26.24: ListTest.java
2 // Selecting colors from a JList.
3 import javax.swing.JFrame;
4
5 public class ListTest
6 {
7 public static void main(String[] args)
8 {
9 ListFrame listFrame = new ListFrame(); // create ListFrame
10 listFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11 listFrame.setSize(350, 150);
12 listFrame.setVisible(true);
13 }
14 }

Line 29 (Fig. 26.23) creates JList object colorJList. The argument to the JList constructor is the array of Objects (in this case Strings) to display in the list. Line 30 uses JList method setVisibleRowCount to determine the number ...
Read now
Unlock full access