List of usage examples for javax.swing JList setModel
@BeanProperty(visualUpdate = true, description = "The object that contains the data to be drawn by this JList.") public void setModel(ListModel<E> model)
From source file:net.sf.maltcms.chromaui.charts.GradientPaintScale.java
/** * * @param args/*from w w w .ja v a2 s . c om*/ */ public static void main(String[] args) { double[] st = ImageTools.createSampleTable(256); Logger.getLogger(GradientPaintScale.class.getName()).info(Arrays.toString(st)); double min = 564.648; double max = 24334.234; GradientPaintScale gps = new GradientPaintScale(st, min, max, new Color[] { Color.BLACK, Color.RED, Color.orange, Color.yellow, Color.white }); double val = min; double incr = (max - min) / (st.length - 1); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Increment: {0}", incr); for (int i = 0; i < st.length; i++) { Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Value: {0}", val); gps.getPaint(val); val += incr; } Logger.getLogger(GradientPaintScale.class.getName()).info("Printing min and max values"); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Min: {0} gps min: {1}", new Object[] { min, gps.getPaint(min) }); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Max: {0} gps max: {1}", new Object[] { max, gps.getPaint(max) }); JList jl = new JList(); DefaultListModel dlm = new DefaultListModel(); jl.setModel(dlm); jl.setCellRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof JLabel) { // Border b = // BorderFactory.createCompoundBorder(BorderFactory // .createEmptyBorder(0, 0, 5, 0), BorderFactory // .createLineBorder(Color.BLACK, 1)); // ((JLabel) value).setBorder(b); return (Component) value; } return new JLabel(value.toString()); } }); JFrame jf = new JFrame(); jf.add(new JScrollPane(jl)); jf.setVisible(true); jf.setSize(200, 400); for (int alpha = -10; alpha <= 10; alpha++) { for (int beta = 1; beta <= 20; beta++) { gps.setAlphaBeta(alpha, beta); // System.out.println(Arrays.toString(gps.st)); // System.out.println(Arrays.toString(gps.sampleTable)); BufferedImage bi = gps.getLookupImage(); ImageIcon ii = new ImageIcon(bi); dlm.addElement(new JLabel(ii)); } } }
From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java
/** * /* ww w. j a va 2 s . co m*/ * @param name * @param model * @param cellRenderer * @return */ public static JList list(final String name, final ListModel model, final ListCellRenderer cellRenderer) { final JList list = new JList(); list.setName(name); list.setModel(model); if (cellRenderer != null) { list.setCellRenderer(cellRenderer); } return list; }
From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java
private static void updateListModel(JList list, List<?> newContents) { if (newContents == null) { newContents = ImmutableList.of(); }/*from w ww .ja v a 2 s.c o m*/ ListModel oldModel = list.getModel(); List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize()); for (int i = 0; i < oldModel.getSize(); i++) { old.add(oldModel.getElementAt(i)); } if (old.equals(newContents)) { return; } Object[] selected = list.getSelectedValues(); DefaultListModel listModel = new DefaultListModel(); for (Object obj : newContents) { listModel.addElement(obj); } list.setModel(listModel); List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length); Set<Object> selectedSet = Sets.newHashSet(selected); for (int i = 0; i < listModel.size(); i++) { if (selectedSet.contains(listModel.elementAt(i))) { newIndices.add(i); } } list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0]))); }
From source file:Main.java
Main(String s) { super(s);// w ww. j a va 2 s .co m ListModel lm = new StaticListModel(); JList list = new JList(); list.setModel(lm); list.setCellRenderer(new MyCellRenderer()); getContentPane().add(new JScrollPane(list)); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:MainClass.java
MainClass(String s) { super(s);/*from w w w . ja v a2 s.c o m*/ ListModel lm = new StaticListModel(); JList list = new JList(); list.setModel(lm); list.setCellRenderer(new MyCellRenderer()); getContentPane().add(new JScrollPane(list)); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:InvokeLaterExample.java
public InvokeLaterExample() { JButton button = new JButton(new LongRunningModelFillAction()); add(button);/* ww w.jav a 2 s . c om*/ JList list = new JList(); this.listModel = new DefaultListModel(); this.listModel.addElement("An Empty List Model"); list.setModel(listModel); add(new JScrollPane(list)); add(new JLabel("Status:")); this.statusArea = new JLabel(); add(this.statusArea); }
From source file:SwingWorkerExample.java
public SwingWorkerExample() { JButton button = new JButton(new LongRunningModelFillAction()); add(button);/*from w w w . jav a 2s . c om*/ JList list = new JList(); this.listModel = new DefaultListModel(); this.listModel.addElement("An Empty List Model"); list.setModel(listModel); add(new JScrollPane(list)); add(new JLabel("Status:")); this.statusArea = new JLabel(); add(this.statusArea); }
From source file:com.t3.client.ui.AddResourceDialog.java
public void initLibraryList() { JList list = getLibraryList(); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setModel(new MessageListModel(I18N.getText("dialog.addresource.downloading"))); }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
private JList buildJList(final Dimension dimension, final Object[] items, final JList list, final boolean sort) { if (items == null) { return null; }//from w w w . j a va2s . co m list.setModel(new DefaultListModel() { @Override public void addElement(Object obj) { boolean inserted = false; if (sort) { for (int i = 0; i < this.getSize() && !inserted; i++) { try { final String comparator = ((obj == null) ? "" : obj.toString()); if (this.get(i).toString().compareTo(comparator) > 0) { this.add(i, obj); inserted = true; } } catch (Throwable t) { log.error("Error al ordenar a " + obj + " y no lo incluimos", t); inserted = true; } } } if (!inserted) { super.addElement(obj); } } }); log.trace("Lista con " + items.length + " objetos"); for (Object obj : items) { ((DefaultListModel) list.getModel()).addElement(obj); } list.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = -987995602141400182L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel c = new JLabel(); c.setText(value.toString()); if (isSelected) { c.setOpaque(true); c.setBackground(Color.YELLOW); } return c; } }); list.setMinimumSize(dimension); list.setFixedCellHeight(22); return list; }
From source file:SuitaDetails.java
private void showLib() { JScrollPane jScrollPane1 = new JScrollPane(); JList jList1 = new JList(); JPanel libraries = new JPanel(); jScrollPane1.setViewportView(jList1); GroupLayout layout = new GroupLayout(libraries); libraries.setLayout(layout);/*from w ww . java 2s . co m*/ layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)); try { Object[] s = (Object[]) RunnerRepository.getRPCClient().execute("getLibrariesList", new Object[] { RunnerRepository.user }); String[] libs = new String[s.length]; for (int i = 0; i < s.length; i++) { libs[i] = s[i].toString(); } ArrayList<Integer> ind = new ArrayList<Integer>(); jList1.setModel(new DefaultComboBoxModel(libs)); for (String st : globallib) { for (int i = 0; i < libs.length; i++) { if (libs[i].equals(st)) { ind.add(new Integer(i)); } } } int[] indices = new int[ind.size()]; for (int i = 0; i < ind.size(); i++) { indices[i] = ind.get(i); } jList1.setSelectedIndices(indices); } catch (Exception e) { System.out.println("There was an error on calling getLibrariesList on CE"); e.printStackTrace(); } int resp = (Integer) CustomDialog.showDialog(libraries, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, RunnerRepository.window, "Libraries", null); if (resp == JOptionPane.OK_OPTION) { Object[] val = jList1.getSelectedValues(); globallib = new String[val.length]; for (int s = 0; s < val.length; s++) { globallib[s] = val[s].toString(); } } }