Results 1 to 3 of 3

Thread: [RESOLVED] Best way to create a check list?

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Best way to create a check list?

    Hi,

    What is the best way to create a checklist in terms of software develpment when there are hundreds of items? I have thought about check boxes although, this would be a hassle in terms for setup everything. This is an example of the type of check list I am talking about.

    Nightwalker
    Last edited by Nightwalker83; Mar 9th, 2012 at 06:12 AM. Reason: Fixed spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Best way to create a check list?

    Hello Nightwalker83,

    As requested, I have moved your thread to the Java Forum.

    Gary

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Best way to create a check list?

    I finally found code that creates the check lists, here it is.

    java Code:
    1. package checklistexample2;
    2.  
    3. /*
    4.  * To change this template, choose Tools | Templates
    5.  * and open the template in the editor.
    6.  */
    7.  
    8. /** Example from [url]http://www.crionics.com/products/opensource/faq/swing_ex/SwingExamples.html[/url]
    9.  
    10. //File:CheckListExample2.java
    11. /* (swing1.1.1beta2) */
    12.  
    13.  
    14. import java.awt.BorderLayout;
    15. import java.awt.Component;
    16. import java.awt.GridLayout;
    17. import java.awt.Rectangle;
    18. import java.awt.event.ActionEvent;
    19. import java.awt.event.ActionListener;
    20. import java.awt.event.MouseAdapter;
    21. import java.awt.event.MouseEvent;
    22. import java.awt.event.WindowAdapter;
    23. import java.awt.event.WindowEvent;
    24.  
    25. import javax.swing.JButton;
    26. import javax.swing.JCheckBox;
    27. import javax.swing.JFrame;
    28. import javax.swing.JList;
    29. import javax.swing.JPanel;
    30. import javax.swing.JScrollPane;
    31. import javax.swing.JTextArea;
    32. import javax.swing.ListCellRenderer;
    33. import javax.swing.ListModel;
    34. import javax.swing.ListSelectionModel;
    35. import javax.swing.UIManager;
    36. import javax.swing.border.EmptyBorder;
    37.  
    38. /**
    39.  * @version 1.0 04/26/99
    40.  */
    41. public class CheckListExample2 extends JFrame {
    42.  
    43.   public CheckListExample2() {
    44.     super("CheckList Example");
    45.     String[] strs = { "swing", "home", "basic", "metal", "JList" };
    46.  
    47.     final JList list = new JList(createData(strs));
    48.  
    49.     list.setCellRenderer(new CheckListRenderer());
    50.     list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    51.     list.setBorder(new EmptyBorder(0, 4, 0, 0));
    52.     list.addMouseListener(new MouseAdapter() {
    53.       public void mouseClicked(MouseEvent e) {
    54.         int index = list.locationToIndex(e.getPoint());
    55.         CheckableItem item = (CheckableItem) list.getModel()
    56.             .getElementAt(index);
    57.         item.setSelected(!item.isSelected());
    58.         Rectangle rect = list.getCellBounds(index, index);
    59.         list.repaint(rect);
    60.       }
    61.     });
    62.     JScrollPane sp = new JScrollPane(list);
    63.  
    64.     final JTextArea textArea = new JTextArea(3, 10);
    65.     JScrollPane textPanel = new JScrollPane(textArea);
    66.     JButton printButton = new JButton("print");
    67.     printButton.addActionListener(new ActionListener() {
    68.       public void actionPerformed(ActionEvent e) {
    69.         ListModel model = list.getModel();
    70.         int n = model.getSize();
    71.         for (int i = 0; i < n; i++) {
    72.           CheckableItem item = (CheckableItem) model.getElementAt(i);
    73.           if (item.isSelected()) {
    74.             textArea.append(item.toString());
    75.             textArea.append(System.getProperty("line.separator"));
    76.           }
    77.         }
    78.       }
    79.     });
    80.     JButton clearButton = new JButton("clear");
    81.     clearButton.addActionListener(new ActionListener() {
    82.       public void actionPerformed(ActionEvent e) {
    83.         textArea.setText("");
    84.       }
    85.     });
    86.     JPanel panel = new JPanel(new GridLayout(2, 1));
    87.     panel.add(printButton);
    88.     panel.add(clearButton);
    89.  
    90.     getContentPane().add(sp, BorderLayout.CENTER);
    91.     getContentPane().add(panel, BorderLayout.EAST);
    92.     getContentPane().add(textPanel, BorderLayout.SOUTH);
    93.   }
    94.  
    95.   private CheckableItem[] createData(String[] strs) {
    96.     int n = strs.length;
    97.     CheckableItem[] items = new CheckableItem[n];
    98.     for (int i = 0; i < n; i++) {
    99.       items[i] = new CheckableItem(strs[i]);
    100.     }
    101.     return items;
    102.   }
    103.  
    104.   class CheckableItem {
    105.     private String str;
    106.  
    107.     private boolean isSelected;
    108.  
    109.     public CheckableItem(String str) {
    110.       this.str = str;
    111.       isSelected = false;
    112.     }
    113.  
    114.     public void setSelected(boolean b) {
    115.       isSelected = b;
    116.     }
    117.  
    118.     public boolean isSelected() {
    119.       return isSelected;
    120.     }
    121.  
    122.     public String toString() {
    123.       return str;
    124.     }
    125.   }
    126.  
    127.   class CheckListRenderer extends JCheckBox implements ListCellRenderer {
    128.  
    129.     public CheckListRenderer() {
    130.       setBackground(UIManager.getColor("List.textBackground"));
    131.       setForeground(UIManager.getColor("List.textForeground"));
    132.     }
    133.  
    134.     public Component getListCellRendererComponent(JList list, Object value,
    135.         int index, boolean isSelected, boolean hasFocus) {
    136.       setEnabled(list.isEnabled());
    137.       setSelected(((CheckableItem) value).isSelected());
    138.       setFont(list.getFont());
    139.       setText(value.toString());
    140.       return this;
    141.     }
    142.   }
    143.  
    144.   public static void main(String args[]) {
    145.     try {
    146.         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    147.     } catch (Exception evt) {}
    148.  
    149.     CheckListExample2 frame = new CheckListExample2();
    150.     frame.addWindowListener(new WindowAdapter() {
    151.       public void windowClosing(WindowEvent e) {
    152.         System.exit(0);
    153.       }
    154.     });
    155.     frame.setSize(300, 200);
    156.     frame.setVisible(true);
    157.   }
    158. }
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width