Example usage for javax.swing SpinnerListModel SpinnerListModel

List of usage examples for javax.swing SpinnerListModel SpinnerListModel

Introduction

In this page you can find the example usage for javax.swing SpinnerListModel SpinnerListModel.

Prototype

public SpinnerListModel(Object[] values) 

Source Link

Document

Constructs a SpinnerModel whose sequence of values is defined by the specified array.

Usage

From source file:com.anrisoftware.prefdialog.fields.spinner.SpinnerField.java

private SpinnerModel createListModel() {
    String field = annotationAccess.getValue("elements");
    if (isBlank(field)) {
        return null;
    }/*from  w w  w  .  java 2s .  c  om*/
    return new SpinnerListModel(beanAccessFactory.create(field, getParentObject()).<List<?>>getValue());
}

From source file:TextInputDemo.java

protected JComponent createEntryFields() {
    JPanel panel = new JPanel(new SpringLayout());

    String[] labelStrings = { "Street address: ", "City: ", "State: ", "Zip code: " };

    JLabel[] labels = new JLabel[labelStrings.length];
    JComponent[] fields = new JComponent[labelStrings.length];
    int fieldNum = 0;

    //Create the text field and set it up.
    streetField = new JTextField();
    streetField.setColumns(20);/*from   w w w .  j ava2s  .  co m*/
    fields[fieldNum++] = streetField;

    cityField = new JTextField();
    cityField.setColumns(20);
    fields[fieldNum++] = cityField;

    String[] stateStrings = getStateStrings();
    stateSpinner = new JSpinner(new SpinnerListModel(stateStrings));
    fields[fieldNum++] = stateSpinner;

    zipField = new JFormattedTextField(createFormatter("#####"));
    fields[fieldNum++] = zipField;

    //Associate label/field pairs, add everything,
    //and lay it out.
    for (int i = 0; i < labelStrings.length; i++) {
        labels[i] = new JLabel(labelStrings[i], JLabel.TRAILING);
        labels[i].setLabelFor(fields[i]);
        panel.add(labels[i]);
        panel.add(fields[i]);

        //Add listeners to each field.
        JTextField tf = null;
        if (fields[i] instanceof JSpinner) {
            tf = getTextField((JSpinner) fields[i]);
        } else {
            tf = (JTextField) fields[i];
        }
        tf.addActionListener(this);
        tf.addFocusListener(this);
    }
    SpringUtilities.makeCompactGrid(panel, labelStrings.length, 2, GAP, GAP, //init x,y
            GAP, GAP / 2);//xpad, ypad
    return panel;
}

From source file:es.unex.meigas.extFillData.FittingDataPanel.java

private JSpinner getJSpinnerOrder() {

    if (jSpinnerOrder == null) {
        final SpinnerListModel jSpinnerOrderModel = new SpinnerListModel(
                new String[] { "1", "2", "3", "4", "5", "6", "7" });
        jSpinnerOrder = new JSpinner();
        jSpinnerOrder.setModel(jSpinnerOrderModel);
        jSpinnerOrder.addChangeListener(new ChangeListener() {
            public void stateChanged(final ChangeEvent evt) {
                String s = (String) ((SpinnerListModel) jSpinnerOrder.getModel()).getValue();
                m_Lsf.calculate(Integer.parseInt(s));
                updateDataset();//from   w w w  . j ava2 s  .  c  o  m
                s = m_Lsf.getExpression();
                getJLabel().setText("Ecuacion de ajuste: y = " + s);
            }
        });
    }

    return jSpinnerOrder;

}

From source file:coreferenceresolver.gui.MarkupGUI.java

private JScrollPane newMarkupPanel(NounPhrase np, ReviewElement reviewElement) {
    //MODEL//ww  w  .j ava 2s.  c  o m
    Element element = new Element();

    //Newly added
    ScrollablePanel markupPanel = new ScrollablePanel();
    markupPanel.setLayout(new BoxLayout(markupPanel, BoxLayout.X_AXIS));
    markupPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT);

    JTextArea npContentTxtArea = new JTextArea();
    npContentTxtArea.setEditable(false);
    npContentTxtArea.setText(((MarkupNounPhrase) np).content);
    markupPanel.add(npContentTxtArea);

    //REF
    SpinnerModel refSpinnerModel = new SpinnerNumberModel(np.getChainId(), -1, COLORS.length - 1, 1);
    JSpinner refSpinner = new JSpinner(refSpinnerModel);
    refSpinner.setValue(np.getChainId());

    refSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            np.setChainId((int) refSpinner.getValue());
            try {
                rePaint(reviewElements.get(np.getReviewId()), np);
            } catch (BadLocationException ex) {
                Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    element.refSpinner = refSpinner;

    //TYPE        
    String[] typeValues = { "Object", "Other", "Candidate", "Attribute" };
    SpinnerModel typeSpinnerModel = new SpinnerListModel(typeValues);
    JSpinner typeSpinner = new JSpinner(typeSpinnerModel);
    typeSpinner.setValue(typeValues[np.getType()]);

    element.typeSpinner = typeSpinner;

    //REF + TYPE
    ScrollablePanel spinners = new ScrollablePanel();
    spinners.setLayout(new BoxLayout(spinners, BoxLayout.X_AXIS));
    spinners.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT);
    spinners.add(refSpinner);
    spinners.add(typeSpinner);
    markupPanel.add(spinners);

    reviewElement.addElement(element);

    JScrollPane scrollMarkupPanel = new JScrollPane(markupPanel);

    return scrollMarkupPanel;
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.spinner.ListSpinnerComposite.java

@Override
public SpinnerModel getModel() {
    String[] items = getItems();
    return new SpinnerListModel(items);
}

From source file:org.rdv.ui.ControlPanel.java

/**
 * Setup the UI./*  ww  w  .  j a v  a 2s .c  o  m*/
 */
private void initPanel() {
    setLayout(new BorderLayout());

    GridBagConstraints c = new GridBagConstraints();

    JPanel container = new JPanel();
    container.setLayout(new GridBagLayout());

    Box firstRowPanel = new Box(BoxLayout.LINE_AXIS);

    beginButton = new JButton();
    beginButton.setName("beginButton");
    beginButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLocationBegin();
        }
    });
    firstRowPanel.add(beginButton);

    rtButton = new JButton();
    rtButton.setName("rtButton");
    rtButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (rtButton.isSelected()) {
                rbnbController.pause();
            } else {
                rbnbController.monitor();
            }
        }
    });
    firstRowPanel.add(rtButton);

    playButton = new JButton();
    playButton.setName("playButton");
    playButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (playButton.isSelected()) {
                rbnbController.pause();
            } else {
                rbnbController.play();
            }
        }
    });
    firstRowPanel.add(playButton);

    endButton = new JButton();
    endButton.setName("endButton");
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLocationEnd();
        }
    });
    firstRowPanel.add(endButton);

    firstRowPanel.add(Box.createHorizontalStrut(8));

    SpinnerListModel playbackRateModel = new SpinnerListModel(playbackRates);
    playbackRateSpinner = new JSpinner(playbackRateModel);
    playbackRateSpinner.setName("playbackRateSpinner");
    JSpinner.ListEditor playbackRateEditor = new JSpinner.ListEditor(playbackRateSpinner);
    playbackRateEditor.getTextField().setEditable(false);
    playbackRateSpinner.setEditor(playbackRateEditor);
    playbackRateSpinner.setPreferredSize(new Dimension(80, playbackRateSpinner.getPreferredSize().height));
    playbackRateSpinner.setMinimumSize(playbackRateSpinner.getPreferredSize());
    playbackRateSpinner.setMaximumSize(playbackRateSpinner.getPreferredSize());
    playbackRateSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            playbackRateChanged();
        }
    });
    firstRowPanel.add(playbackRateSpinner);

    firstRowPanel.add(Box.createHorizontalStrut(8));

    timeScaleComboBox = new JComboBox();
    timeScaleComboBox.setName("timeScaleComboBox");
    timeScaleComboBox.setEditable(true);
    timeScaleComboBox.setPreferredSize(new Dimension(96, timeScaleComboBox.getPreferredSize().height));
    timeScaleComboBox.setMinimumSize(timeScaleComboBox.getPreferredSize());
    timeScaleComboBox.setMaximumSize(timeScaleComboBox.getPreferredSize());
    for (int i = 0; i < timeScales.length; i++) {
        timeScaleComboBox.addItem(DataViewer.formatSeconds(timeScales[i]));
    }
    timeScaleComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            timeScaleChange();
        }
    });
    firstRowPanel.add(timeScaleComboBox);

    firstRowPanel.add(Box.createHorizontalGlue());

    locationButton = new JButton();
    locationButton.setName("locationButton");
    locationButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TimeRange timeRange = RBNBHelper.getChannelsTimeRange();
            double time = DateTimeDialog.showDialog(ControlPanel.this, rbnbController.getLocation(),
                    timeRange.start, timeRange.end);
            if (time >= 0) {
                rbnbController.setLocation(time);
            }
        }
    });
    firstRowPanel.add(locationButton);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 8, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(firstRowPanel, c);

    zoomTimeSlider = new TimeSlider();
    zoomTimeSlider.setRangeChangeable(false);
    zoomTimeSlider.addTimeAdjustmentListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(0, 8, 0, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(zoomTimeSlider, c);

    JPanel zoomTimePanel = new JPanel();
    zoomTimePanel.setLayout(new BorderLayout());

    zoomMinimumLabel = new JLabel();
    zoomMinimumLabel.setName("zoomMinimumLabel");
    zoomTimePanel.add(zoomMinimumLabel, BorderLayout.WEST);

    zoomRangeLabel = new JLabel();
    zoomRangeLabel.setName("zoomRangeLabel");
    zoomRangeLabel.setHorizontalAlignment(JLabel.CENTER);
    zoomTimePanel.add(zoomRangeLabel, BorderLayout.CENTER);

    zoomMaximumLabel = new JLabel();
    zoomMaximumLabel.setName("zoomMaximumLabel");
    zoomTimePanel.add(zoomMaximumLabel, BorderLayout.EAST);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 0, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(zoomTimePanel, c);

    globalTimeSlider = new TimeSlider();
    globalTimeSlider.setValueChangeable(false);
    globalTimeSlider.addTimeAdjustmentListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 8, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(globalTimeSlider, c);

    add(container, BorderLayout.CENTER);

    log.info("Initialized control panel.");
}