List of usage examples for javax.swing JList setMinimumSize
@BeanProperty(description = "The minimum size of the component.") public void setMinimumSize(Dimension minimumSize)
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 ww w. j a v a2 s .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; }