Java JList Select applyDefaultDisplaySettings(JList list, int index, boolean selected, boolean cellHasFocus, JComponent renderer)

Here you can find the source of applyDefaultDisplaySettings(JList list, int index, boolean selected, boolean cellHasFocus, JComponent renderer)

Description

Uses DefaultListCellRenderer to apply default settings to the provided renderer component.

License

Apache License

Parameter

Parameter Description
list list.
index index.
selected selected.
cellHasFocus focus.
renderer renderer component.

Declaration

public static void applyDefaultDisplaySettings(JList list, int index, boolean selected, boolean cellHasFocus,
        JComponent renderer) 

Method Source Code

//package com.java2s;
/*/*w  ww.  ja v a2  s . co m*/
 * Copyright 2008 Michal Trzcinka
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.swing.*;

public class Main {
    private static final ListCellRenderer defaultRenderer = new DefaultListCellRenderer();

    /**
     * Uses {@link DefaultListCellRenderer} to apply default settings to the provided renderer component.
     *
     * @param list         list.
     * @param index        index.
     * @param selected     selected.
     * @param cellHasFocus focus.
     * @param renderer     renderer component.
     */
    public static void applyDefaultDisplaySettings(JList list, int index, boolean selected, boolean cellHasFocus,
            JComponent renderer) {

        JComponent defRendererComponent = (JComponent) defaultRenderer.getListCellRendererComponent(list,
                cellHasFocus, index, selected, cellHasFocus);
        renderer.setForeground(defRendererComponent.getForeground());
        renderer.setBackground(defRendererComponent.getBackground());
        renderer.setComponentOrientation(defRendererComponent.getComponentOrientation());
        if (cellHasFocus) {
            renderer.requestFocus();
        }
        renderer.setBorder(defRendererComponent.getBorder());
        renderer.setEnabled(defRendererComponent.isEnabled());
        renderer.setFont(defRendererComponent.getFont());
    }
}

Related

  1. adaptToList(final JComponent renderer, JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
  2. canMoveSelectedItemsUp(JList list)
  3. createStringFromSelectionList( JList aListComponent, boolean createQuotes)
  4. downListSelectedIndex(JList sourceList)
  5. ensureSelectionIsVisible(final JList list)