Java JScrollPane makeListInScrollPane(Collection items, Function namer)

Here you can find the source of makeListInScrollPane(Collection items, Function namer)

Description

make List In Scroll Pane

License

Open Source License

Declaration

static public <T, U> JScrollPane makeListInScrollPane(Collection<T> items, Function<T, U> namer) 

Method Source Code

//package com.java2s;
/*//  w w w . j a  va  2 s  .c o m
KDXplore provides KDDart Data Exploration and Management
Copyright (C) 2015,2016,2017  Diversity Arrays Technology, Pty Ltd.
    
KDXplore may be redistributed and may be modified under the terms
of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.
    
KDXplore is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with KDXplore.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Collection;

import java.util.function.Function;

import javax.swing.DefaultListModel;

import javax.swing.JList;

import javax.swing.JScrollPane;

public class Main {
    private static final int DEFAULT_MAX_VIEW = 10;

    static public <T, U> JScrollPane makeListInScrollPane(Collection<T> items, Function<T, U> namer) {
        return makeListInScrollPane(items, namer, DEFAULT_MAX_VIEW);
    }

    static public <T, U> JScrollPane makeListInScrollPane(Collection<T> items, Function<T, U> namer, int maxView) {
        DefaultListModel<U> listModel = new DefaultListModel<>();
        items.stream().forEach(item -> listModel.addElement(namer.apply(item)));
        JList<U> list = new JList<>(listModel);
        if (maxView > 0) {
            list.setVisibleRowCount(Math.min(maxView, listModel.size()));
        }
        return new JScrollPane(list);
    }
}

Related

  1. hasParentScrollPane(JComponent component)
  2. initScrollPane(JScrollPane scrollPane)
  3. isHorizontalScrollBarHiddenAlways(JScrollPane pane)
  4. isScrolledToBottom(final JScrollPane scrollPane)
  5. makeComponentDragScrollable(final JComponent component)
  6. makeVScroller(Component c)
  7. moveEnd(JScrollPane pane)
  8. newJScrollPane(String title, Component c)
  9. resetScrollPane(final JScrollPane scrollPane)