Example usage for javax.swing SpinnerNumberModel SpinnerNumberModel

List of usage examples for javax.swing SpinnerNumberModel SpinnerNumberModel

Introduction

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

Prototype

public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize) 

Source Link

Document

Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.

Usage

From source file:SwingSpinnerTest.java

public SwingSpinnerTest() {
    super("JSpinner Test");
    setSize(300, 180);/*from ww w .j  av a2  s  . com*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    c.add(new JLabel(" Basic Spinner"));
    c.add(new JSpinner());

    c.add(new JLabel(" Date Spinner"));
    c.add(new JSpinner(new SpinnerDateModel()));

    String weekdays[] = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
            "Saturday" };
    c.add(new JLabel(" List Spinner"));
    c.add(new JSpinner(new SpinnerListModel(weekdays)));

    c.add(new JLabel(" Number Spinner"));
    c.add(new JSpinner(new SpinnerNumberModel(0, 0, 100, 5)));

    c.add(new JLabel(" Rollover List Spinner"));
    c.add(new JSpinner(new RolloverSpinnerListModel(weekdays)));

    setVisible(true);
}

From source file:ir.ac.iust.nlp.postagger.POSTaggerForm.java

public POSTaggerForm() {
    initComponents();/*from  w ww.j  av  a2  s .c o m*/

    SpinnerNumberModel num_model = new SpinnerNumberModel(100, 1, 10000000, 1);
    spMaxIters.setModel(num_model);

    wordModel = (DefaultListModel) lstWordsList.getModel();
    predModel = (DefaultListModel) lstPredictedTags.getModel();
    goldModel = (DefaultListModel) lstGoldTags.getModel();

    setDrop();

    String curDir = System.getProperty("user.dir");
    txtInputCoNLLFile.setText(
            curDir + File.separator + "data" + File.separator + "conll" + File.separator + "test.conll");
    txtOutputTagPath.setText(curDir + File.separator);
    txtOutputDepPath.setText(curDir + File.separator);
    txtOutputPath.setText(curDir + File.separator);
    txtInputTagFile.setText(
            curDir + File.separator + "data" + File.separator + "tag" + File.separator + "gold_test.lbl");
    txtInputCoNLLFileT2D.setText(
            curDir + File.separator + "data" + File.separator + "conll" + File.separator + "test.conll");
    txtTrainFile
            .setText(curDir + File.separator + "data" + File.separator + "tag" + File.separator + "train.lbl");
    txtTrainModelPath.setText(curDir + File.separator + "model" + File.separator);
    txtModelPath.setText(curDir + File.separator + "data" + File.separator + "model" + File.separator);
    txtInputFile
            .setText(curDir + File.separator + "data" + File.separator + "tag" + File.separator + "test.lbl");
    txtGoldFile.setText(
            curDir + File.separator + "data" + File.separator + "tag" + File.separator + "gold_test.lbl");
}

From source file:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java

public SingleHistogramPanel(Matrix m) {
    super(new BorderLayout());
    this.m = m;/*  ww w.j  a va2 s  .c  om*/
    this.chart = createChart();
    this.chartPanel = new ChartPanel(this.chart);

    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    this.chartPanel.setBorder(border);
    add(this.chartPanel, BorderLayout.CENTER);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));

    this.spinner = new JSpinner(new SpinnerNumberModel(0, 0, m.getColCount() - 1, 1));
    spinner.addChangeListener(this);
    this.slider = new JSlider(0, m.getColCount() - 1, 0);
    slider.setPaintLabels(true);

    slider.setMajorTickSpacing(Math.max(50, 10 * Math.round(m.getColCount() / 100)));
    slider.setPaintTicks(true);
    this.slider.addChangeListener(this);

    FormLayout layout = new FormLayout("fill:0:g, max(20dlu; pref)", "top:pref");
    CellConstraints cc = new CellConstraints();
    DefaultFormBuilder fb = new DefaultFormBuilder(layout, Translation.INSTANCE.getBundle());

    fb.add(slider, cc.xy(1, 1));
    fb.add(spinner, cc.xy(2, 1));

    dashboard.add(fb.getPanel(), BorderLayout.CENTER);
    add(dashboard, BorderLayout.SOUTH);
    switchColumn(0);
}

From source file:Main.java

public Main() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);//from   www  .ja  v a  2 s .co  m
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JSpinner defaultSpinner = new JSpinner();
    addRow("Default", defaultSpinner);

    JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5));
    addRow("Bounded", boundedSpinner);

    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts));
    addRow("List", listSpinner);

    JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) {
        public Object getNextValue() {
            return super.getPreviousValue();
        }

        public Object getPreviousValue() {
            return super.getNextValue();
        }
    });
    addRow("Reverse List", reverseListSpinner);

    JSpinner dateSpinner = new JSpinner(new SpinnerDateModel());
    addRow("Date", dateSpinner);

    JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel());
    String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern();
    betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern));
    addRow("Better Date", betterDateSpinner);

    JSpinner timeSpinner = new JSpinner(new SpinnerDateModel());
    pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern();
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern));
    addRow("Time", timeSpinner);

    JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat"));
    addRow("Word permutations", permSpinner);
}

From source file:QandE.Beeper2.java

public Beeper2() {
    super(new BorderLayout());

    //Create and set up the spinner.
    String numBeepsString = "Number of Beeps: ";
    beepsModel = new SpinnerNumberModel(1, 1, 10, 1);
    JLabel numBeepsLabel = new JLabel(numBeepsString);
    add(numBeepsLabel, BorderLayout.PAGE_START);
    JSpinner spinner = new JSpinner(beepsModel);
    numBeepsLabel.setLabelFor(spinner);/*from w ww.  ja v  a 2s  .c  om*/
    add(spinner, BorderLayout.CENTER);

    button = new JButton("Click Me");
    button.setPreferredSize(new Dimension(200, 80));
    add(button, BorderLayout.PAGE_END);
    button.setActionCommand(BUTTON_CMD);
    button.addActionListener(this);
}

From source file:SpinnerTest.java

public SpinnerFrame() {
    setTitle("SpinnerTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);//from  www. ja va  2  s . c o m
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JSpinner defaultSpinner = new JSpinner();
    addRow("Default", defaultSpinner);

    JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5));
    addRow("Bounded", boundedSpinner);

    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts));
    addRow("List", listSpinner);

    JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) {
        public Object getNextValue() {
            return super.getPreviousValue();
        }

        public Object getPreviousValue() {
            return super.getNextValue();
        }
    });
    addRow("Reverse List", reverseListSpinner);

    JSpinner dateSpinner = new JSpinner(new SpinnerDateModel());
    addRow("Date", dateSpinner);

    JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel());
    String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern();
    betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern));
    addRow("Better Date", betterDateSpinner);

    JSpinner timeSpinner = new JSpinner(new SpinnerDateModel());
    pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern();
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern));
    addRow("Time", timeSpinner);

    JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat"));
    addRow("Word permutations", permSpinner);
}

From source file:edu.ku.brc.af.ui.forms.validation.ValSpinner.java

/**
 * Constructor./*from w ww  .  ja  va2s .  com*/
 * @param minVal the min value
 * @param maxVal the max value
 * @param isRequired is required
 * @param isReadOnly is read only
 */
public ValSpinner(final int minVal, final int maxVal, final boolean isRequired, final boolean isReadOnly) {
    super(new SpinnerNumberModel(minVal, // initial value
            minVal, // min
            maxVal, // max
            1)); // step
    this.isRequired = isRequired;
    this.isReadOnly = isReadOnly;
    this.minValue = minVal;
    this.maxValue = maxVal;

    init();

    textField = getTextField(this);
    if (textField != null) {
        bgColor = textField.getBackground();
    }

    if (this.isRequired) {
        fixBGOfJSpinner();
    }
}

From source file:org.cytoscape.dyn.internal.graphMetrics.SaveChartDialog.java

public SaveChartDialog(JFrame frame, JFreeChart chart) {
    super(frame, "Save Chart to File", false);
    this.chart = chart;
    JPanel sizePanel = new JPanel(new GridLayout(2, 3, 4, 4));
    sizePanel.setBorder(BorderFactory.createTitledBorder("Image Size"));

    // Add a spinner for choosing width
    sizePanel.add(new JLabel("Width:", SwingConstants.RIGHT));
    int width = ChartPanel.DEFAULT_WIDTH;
    int minWidth = ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH;
    int maxWidth = ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH;
    SpinnerModel widthSettings = new SpinnerNumberModel(width, minWidth, maxWidth, 1);
    sizePanel.add(widthSpinner = new JSpinner(widthSettings));
    sizePanel.add(new JLabel("pixels"));

    // Add a spinner for choosing height
    sizePanel.add(new JLabel("Height:", SwingConstants.RIGHT));
    int height = ChartPanel.DEFAULT_HEIGHT;
    int minHeight = ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT;
    int maxHeight = ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT;
    SpinnerModel heightSettings = new SpinnerNumberModel(height, minHeight, maxHeight, 1);
    sizePanel.add(heightSpinner = new JSpinner(heightSettings));
    sizePanel.add(new JLabel("pixels"));

    JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, 4, 0));
    saveChartButton = new JButton("Save");
    saveChartButton.setMaximumSize(new Dimension(Short.MAX_VALUE, saveChartButton.getHeight()));
    saveChartButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.setMaximumSize(new Dimension(Short.MAX_VALUE, cancelButton.getHeight()));
    cancelButton.addActionListener(this);
    buttonsPanel.add(saveChartButton);/* ww  w. j ava 2s  .c o  m*/
    buttonsPanel.add(cancelButton);
    Box buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(Box.createHorizontalGlue());
    buttonsBox.add(buttonsPanel);
    buttonsBox.add(Box.createHorizontalGlue());

    Container contentPane = getContentPane();
    contentPane.add(sizePanel, BorderLayout.NORTH);
    contentPane.add(Box.createVerticalStrut(3));
    contentPane.add(buttonsBox, BorderLayout.PAGE_END);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    getRootPane().setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    pack();
    setModal(true);
    setResizable(false);
    setLocationRelativeTo(frame);

}

From source file:be.fedict.eid.tsl.tool.SignSelectPkcs11FinishablePanel.java

@Override
public Component getComponent() {
    LOG.debug("get component");
    if (null == this.component) {
        /*/*w w  w  . j ava 2 s .  co  m*/
         * We need to return the same component each time, else the
         * validate() logic doesn't work as expected.
         */
        JPanel panel = new JPanel();
        BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
        panel.setLayout(boxLayout);
        JPanel infoPanel = new JPanel();
        infoPanel.add(new JLabel("Please select a PKCS#11 library."));
        panel.add(infoPanel);

        JPanel browsePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        panel.add(browsePanel);
        browsePanel.add(new JLabel("PKCS#11 library:"));
        this.pkcs11TextField = new JTextField(30);
        browsePanel.add(this.pkcs11TextField);
        JButton browseButton = new JButton("Browse...");
        browseButton.addActionListener(this);
        browsePanel.add(browseButton);

        JPanel slotIdxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        panel.add(slotIdxPanel);
        slotIdxPanel.add(new JLabel("Slot index:"));
        SpinnerModel spinnerModel = new SpinnerNumberModel(0, 0, 10, 1);
        this.slotIdxSpinner = new JSpinner(spinnerModel);
        slotIdxPanel.add(this.slotIdxSpinner);

        this.component = panel;
    }
    return this.component;
}

From source file:components.SpinnerDemo.java

public SpinnerDemo(boolean cycleMonths) {
    super(new SpringLayout());

    String[] labels = { "Month: ", "Year: ", "Another Date: " };
    int numPairs = labels.length;
    Calendar calendar = Calendar.getInstance();
    JFormattedTextField ftf = null;

    //Add the first label-spinner pair.
    String[] monthStrings = getMonthStrings(); //get month names
    SpinnerListModel monthModel = null;
    if (cycleMonths) { //use custom model
        monthModel = new CyclingSpinnerListModel(monthStrings);
    } else { //use standard model
        monthModel = new SpinnerListModel(monthStrings);
    }//ww  w  .  j av  a  2s. com
    JSpinner spinner = addLabeledSpinner(this, labels[0], monthModel);
    //Tweak the spinner's formatted text field.
    ftf = getTextField(spinner);
    if (ftf != null) {
        ftf.setColumns(8); //specify more width than we need
        ftf.setHorizontalAlignment(JTextField.RIGHT);
    }

    //Add second label-spinner pair.
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
            currentYear - 100, //min
            currentYear + 100, //max
            1); //step
    //If we're cycling, hook this model up to the month model.
    if (monthModel instanceof CyclingSpinnerListModel) {
        ((CyclingSpinnerListModel) monthModel).setLinkedModel(yearModel);
    }
    spinner = addLabeledSpinner(this, labels[1], yearModel);
    //Make the year be formatted without a thousands separator.
    spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));

    //Add the third label-spinner pair.
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -100);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 200);
    Date latestDate = calendar.getTime();
    SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input
    spinner = addLabeledSpinner(this, labels[2], dateModel);
    spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy"));

    //Lay out the panel.
    SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols
            10, 10, //initX, initY
            6, 10); //xPad, yPad
}