Changeset 9185


Ignore:
Timestamp:
2005-02-25T14:24:48+13:00 (19 years ago)
Author:
mdewsnip
Message:

Fix to the bug with Java 1.5.0 where the checkbox would not repaint if it was clicked while the item was selected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/CheckList.java

    r8884 r9185  
    6666    setModel(new DefaultListModel());
    6767    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    68     addMouseListener(new CheckListListener());
     68    addMouseListener(new CheckListMouseListener());
    6969    }
    7070
     
    153153
    154154
    155     private void selectionChanged(int index) {
    156     fireSelectionValueChanged(index, index, false);
    157     }
    158 
    159 
    160155    /** A custom list cell renderer for producing rows which contain clickable check boxes. */
    161156    protected class CheckListCellRenderer
    162     implements ListCellRenderer {
    163 
     157    implements ListCellRenderer
     158    {
    164159    /** Return a component that has been configured to display the specified value. That component's paint method is then called to "render" the cell. If it is necessary to compute the dimensions of a list because the list cells do not have a fixed size, this method is called to generate a component on which getPreferredSize  can be invoked.
    165160     * @param list The </strong>JList</strong> we're painting.
     
    172167    public Component getListCellRendererComponent(JList list, Object value, int index, boolean is_selected, boolean cell_has_focus) {
    173168        JCheckBox checkbox = (JCheckBox) value;
    174         if(show_selected_row) {
     169        if (show_selected_row) {
    175170        checkbox.setBackground(is_selected ? list.getSelectionBackground() : list.getBackground());
    176171        checkbox.setForeground(is_selected ? list.getSelectionForeground() : list.getForeground());
     
    192187
    193188    /** Listens for clicks apon the checks within the list, and updates as necessary. */
    194     private class CheckListListener
    195     extends MouseAdapter {
    196 
     189    private class CheckListMouseListener
     190    extends MouseAdapter
     191    {
    197192    /** Called whenever the mouse is clicked over our list. We find the nearest checkbox and change its state.
    198193     * @param e A <strong>MouseEvent</strong> containing everything you ever wanted to know about the mouse event but were afraid to ask.
    199194     */
    200     public void mousePressed(MouseEvent e) {
     195    public void mousePressed(MouseEvent e)
     196    {
    201197        JList list = (JList) e.getSource();
    202198        int index = list.locationToIndex(e.getPoint());
    203         CheckListEntry checkbox = (CheckListEntry)list.getModel().getElementAt(index);
    204         if(!checkbox.isFixed()) {
     199        CheckListEntry checkbox = (CheckListEntry) list.getModel().getElementAt(index);
     200        if (!checkbox.isFixed()) {
    205201        checkbox.setSelected(!checkbox.isSelected());
    206202        }
    207203        checkbox.grabFocus();
    208         // Fire a selection changed event
    209         selectionChanged(index);
     204
     205        // This is necessary to get the checkbox to repaint in Java 1.5.0
     206        list.getSelectionModel().clearSelection();
    210207    }
    211208    }
Note: See TracChangeset for help on using the changeset viewer.