diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-08 22:39:59 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-08 22:39:59 -0300 |
| commit | c82e3b3b2de0633317ec8fc85925e91422820597 (patch) | |
| tree | 96567416ce23c5ce85601f9cedc3a94bb1c55cba /base/src/main/java/bjc/utils/gui/SimpleJList.java | |
| parent | b3ac1c8690c3e14c879913e5dcc03a5f5e14876e (diff) | |
Start splitting into maven modules
Diffstat (limited to 'base/src/main/java/bjc/utils/gui/SimpleJList.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/gui/SimpleJList.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/gui/SimpleJList.java b/base/src/main/java/bjc/utils/gui/SimpleJList.java new file mode 100644 index 0000000..411d0db --- /dev/null +++ b/base/src/main/java/bjc/utils/gui/SimpleJList.java @@ -0,0 +1,49 @@ +package bjc.utils.gui; + +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.ListModel; + +/** + * Utility class for making JLists and their models. + * + * @author ben + * + */ +public class SimpleJList { + /** + * Create a new JList from a given list. + * + * @param <E> + * The type of data in the JList + * + * @param source + * The list to populate the JList with. + * @return A JList populated with the elements from ls. + */ + public static <E> JList<E> buildFromList(final Iterable<E> source) { + if (source == null) throw new NullPointerException("Source must not be null"); + + return new JList<>(buildModel(source)); + } + + /** + * Create a new list model from a given list. + * + * @param <E> + * The type of data in the list model + * + * @param source + * The list to fill the list model from. + * @return A list model populated with the elements from ls. + */ + public static <E> ListModel<E> buildModel(final Iterable<E> source) { + if (source == null) throw new NullPointerException("Source must not be null"); + + final DefaultListModel<E> defaultModel = new DefaultListModel<>(); + + source.forEach(defaultModel::addElement); + + return defaultModel; + } +} |
