Search in sources :

Example 6 with DefaultListModel

use of javax.swing.DefaultListModel in project jdk8u_jdk by JetBrains.

the class bug8057791 method main.

public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(new NimbusLookAndFeel());
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                final int listWidth = 50;
                final int listHeight = 50;
                final int selCellIndex = 0;
                JList<String> list = new JList<String>();
                list.setSize(listWidth, listHeight);
                DefaultListModel<String> listModel = new DefaultListModel<String>();
                listModel.add(selCellIndex, "E");
                list.setModel(listModel);
                list.setSelectedIndex(selCellIndex);
                BufferedImage img = new BufferedImage(listWidth, listHeight, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                list.paint(g);
                g.dispose();
                Rectangle cellRect = list.getCellBounds(selCellIndex, selCellIndex);
                HashSet<Color> cellColors = new HashSet<Color>();
                int uniqueColorIndex = 0;
                for (int x = cellRect.x; x < (cellRect.x + cellRect.width); x++) {
                    for (int y = cellRect.y; y < (cellRect.y + cellRect.height); y++) {
                        Color cellColor = new Color(img.getRGB(x, y), true);
                        if (cellColors.add(cellColor)) {
                            System.err.println(String.format("Cell color #%d: %s", uniqueColorIndex++, cellColor));
                        }
                    }
                }
                Color selForegroundColor = list.getSelectionForeground();
                Color selBackgroundColor = list.getSelectionBackground();
                if (!cellColors.contains(new Color(selForegroundColor.getRGB(), true))) {
                    throw new RuntimeException(String.format("Selected cell is drawn without selection foreground color '%s'.", selForegroundColor));
                }
                if (!cellColors.contains(new Color(selBackgroundColor.getRGB(), true))) {
                    throw new RuntimeException(String.format("Selected cell is drawn without selection background color '%s'.", selBackgroundColor));
                }
            }
        });
    } catch (UnsupportedLookAndFeelException | InterruptedException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : Color(java.awt.Color) Rectangle(java.awt.Rectangle) DefaultListModel(javax.swing.DefaultListModel) BufferedImage(java.awt.image.BufferedImage) InvocationTargetException(java.lang.reflect.InvocationTargetException) Graphics(java.awt.Graphics) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) JList(javax.swing.JList) HashSet(java.util.HashSet)

Example 7 with DefaultListModel

use of javax.swing.DefaultListModel in project OpenAM by OpenRock.

the class ListJPanel method addCategory.

public void addCategory(ImageListEntry entry) {
    ListModel model = categoryjList.getModel();
    if (model instanceof DefaultListModel) {
        ((DefaultListModel) model).addElement(entry);
    } else {
        DefaultListModel newModel = new DefaultListModel();
        newModel.addElement(entry);
        categoryjList.setModel(newModel);
    }
}
Also used : DefaultListModel(javax.swing.DefaultListModel) ListModel(javax.swing.ListModel) DefaultListModel(javax.swing.DefaultListModel)

Example 8 with DefaultListModel

use of javax.swing.DefaultListModel in project SIMRacingApps by SIMRacingApps.

the class JListBinding method get.

public void get(IValidatable bean) {
    try {
        DefaultListModel model = (DefaultListModel) _list.getModel();
        final int size = model.getSize();
        List<Object> list = new ArrayList<Object>(size);
        for (int i = 0; i < size; i++) {
            list.add(model.get(i));
        }
        PropertyUtils.setProperty(bean, _property, list);
    } catch (Exception e) {
        throw new BindingException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel)

Example 9 with DefaultListModel

use of javax.swing.DefaultListModel in project SIMRacingApps by SIMRacingApps.

the class JListBinding method put.

public void put(IValidatable bean) {
    try {
        DefaultListModel model = new DefaultListModel();
        List<?> list = (List<?>) PropertyUtils.getProperty(bean, _property);
        if (list != null) {
            for (Object o : list) {
                model.addElement(o);
            }
        }
        _list.setModel(model);
    } catch (Exception e) {
        throw new BindingException(e);
    }
}
Also used : DefaultListModel(javax.swing.DefaultListModel) List(java.util.List) JList(javax.swing.JList) ArrayList(java.util.ArrayList)

Example 10 with DefaultListModel

use of javax.swing.DefaultListModel in project ACS by ACS-Community.

the class BeanGrouper method getStatusScrollBar.

private JScrollPane getStatusScrollBar() {
    model = new DefaultListModel();
    if (statusList == null) {
        statusList = new JList(model);
        model.addElement("Status: Sampling Group ready to start.");
    }
    if (statusScrollBar == null) {
        statusScrollBar = new JScrollPane(statusList);
    }
    statusList.setVisibleRowCount(1);
    statusScrollBar.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    return statusScrollBar;
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultListModel(javax.swing.DefaultListModel) JList(javax.swing.JList)

Aggregations

DefaultListModel (javax.swing.DefaultListModel)41 JList (javax.swing.JList)21 ArrayList (java.util.ArrayList)16 JScrollPane (javax.swing.JScrollPane)13 List (java.util.List)8 JButton (javax.swing.JButton)8 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 JPanel (javax.swing.JPanel)5 Conditional (jmri.Conditional)5 Dimension (java.awt.Dimension)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 Logix (jmri.Logix)4 Component (java.awt.Component)3 JLabel (javax.swing.JLabel)3 SensorGroupConditional (jmri.implementation.SensorGroupConditional)3 FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2