| 1 | /* CMPUT114(2003-2004, Fall) http://www-csfy.cs.ualberta.ca/~c114/F03 */ |
| 2 | |
| 3 | import java.awt.*; |
| 4 | import javax.swing.*; |
| 5 | import java.applet.*; |
| 6 | |
| 7 | public class JListPanel extends JApplet { |
| 8 | |
| 9 | public void init() { |
| 10 | |
| 11 | this.getContentPane().add(this.getPanel()); |
| 12 | |
| 13 | } |
| 14 | |
| 15 | private JList getList() { |
| 16 | // Create a List with the 5 course items |
| 17 | String[] data = {"Math 113", "Cmput 114", "Phil 120", |
| 18 | "Cmput 272", "Chem 105"}; |
| 19 | |
| 20 | JList tempList = new JList(data); |
| 21 | tempList.setVisibleRowCount(2); |
| 22 | |
| 23 | // Enable single selection |
| 24 | tempList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 25 | return tempList; |
| 26 | } |
| 27 | |
| 28 | private JPanel getPanel() { |
| 29 | // set layout to GridLayout 2 rows and 2 columns |
| 30 | JPanel panel = new JPanel(new GridLayout(2,2,0,0)); |
| 31 | |
| 32 | JScrollPane spane1 = new JScrollPane(this.getList()); |
| 33 | JScrollPane spane2 = new JScrollPane(this.getList()); |
| 34 | panel.add(new JLabel("List 1")); |
| 35 | panel.add(new JLabel("Same List 2")); |
| 36 | panel.add(spane1); |
| 37 | panel.add(spane2); |
| 38 | |
| 39 | return panel; |
| 40 | } |
| 41 | } |