< prev index next >

src/demo/share/jfc/SwingSet2/ListDemo.java

Print this page

        

*** 57,77 **** * on the fly as only those elements are needed. * * @author Jeff Dinkins */ public class ListDemo extends DemoModule { ! JList list; JPanel prefixList; JPanel suffixList; Action prefixAction; Action suffixAction; GeneratedListModel listModel; ! Vector checkboxes = new Vector(); /** * main method allows us to run as a standalone demo. */ public static void main(String[] args) { --- 57,77 ---- * on the fly as only those elements are needed. * * @author Jeff Dinkins */ public class ListDemo extends DemoModule { ! JList<String> list; JPanel prefixList; JPanel suffixList; Action prefixAction; Action suffixAction; GeneratedListModel listModel; ! Vector<JCheckBox> checkboxes = new Vector<>(); /** * main method allows us to run as a standalone demo. */ public static void main(String[] args) {
*** 101,111 **** centerPanel.add(listPanel); centerPanel.add(Box.createRigidArea(HGAP30)); // Create the list ! list = new JList(); list.setCellRenderer(new CompanyLogoListCellRenderer()); listModel = new GeneratedListModel(this); list.setModel(listModel); // Set the preferred row count. This affects the preferredSize --- 101,111 ---- centerPanel.add(listPanel); centerPanel.add(Box.createRigidArea(HGAP30)); // Create the list ! list = new JList<>(); list.setCellRenderer(new CompanyLogoListCellRenderer()); listModel = new GeneratedListModel(this); list.setModel(listModel); // Set the preferred row count. This affects the preferredSize
*** 291,306 **** } } } ! class GeneratedListModel extends AbstractListModel { ListDemo demo; Permuter permuter; ! public Vector prefix = new Vector(); ! public Vector suffix = new Vector(); public GeneratedListModel (ListDemo demo) { this.demo = demo; } --- 291,306 ---- } } } ! class GeneratedListModel extends AbstractListModel<String> { ListDemo demo; Permuter permuter; ! public Vector<String> prefix = new Vector<>(); ! public Vector<String> suffix = new Vector<>(); public GeneratedListModel (ListDemo demo) { this.demo = demo; }
*** 335,345 **** public int getSize() { return prefix.size() * suffix.size(); } ! public Object getElementAt(int index) { if(permuter == null) { update(); } // morph the index to another int -- this has the benefit of // causing the list to look random. --- 335,345 ---- public int getSize() { return prefix.size() * suffix.size(); } ! public String getElementAt(int index) { if(permuter == null) { update(); } // morph the index to another int -- this has the benefit of // causing the list to look random.
*** 361,371 **** images[6] = createImageIcon("list/magenta.gif", getString("ListDemo.magenta")); } class CompanyLogoListCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent( ! JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { --- 361,371 ---- images[6] = createImageIcon("list/magenta.gif", getString("ListDemo.magenta")); } class CompanyLogoListCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent( ! JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
< prev index next >