Java Code Examples for javax.swing.JSpinner#addChangeListener()

The following examples show how to use javax.swing.JSpinner#addChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorPicker.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
public Option(String text,int max) {
	spinner = new JSpinner(new SpinnerNumberModel(0,0,max,5));
	spinner.addChangeListener(changeListener);

                      /*this tries out Tim Boudreaux's new slider UI.
	* It's a good UI, but I think for the ColorPicker
	* the numeric controls are more useful.
	* That is: users who want click-and-drag control to choose
	* their colors don't need any of these Option objects
	* at all; only power users who may have specific RGB
	* values in mind will use these controls: and when they do
	* limiting them to a slider is unnecessary.
	* That's my current position... of course it may
	* not be true in the real world... :)
	*/
	//slider = new JSlider(0,max);
	//slider.addChangeListener(changeListener);
	//slider.setUI(new org.netbeans.paint.api.components.PopupSliderUI());
		
	label = new JLabel(text);
	radioButton.addActionListener(actionListener);
}
 
Example 2
Source File: MultiGradientTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private ControlsPanel() {
    cmbPaint = createCombo(this, paintType);
    cmbPaint.setSelectedIndex(1);
    cmbCycle = createCombo(this, cycleMethod);
    cmbSpace = createCombo(this, colorSpace);
    cmbShape = createCombo(this, shapeType);
    cmbXform = createCombo(this, xformType);

    int max = COLORS.length;
    SpinnerNumberModel model = new SpinnerNumberModel(max, 2, max, 1);
    spinNumColors = new JSpinner(model);
    spinNumColors.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numColors = ((Integer)spinNumColors.getValue()).intValue();
            gradientPanel.updatePaint();
        }
    });
    add(spinNumColors);

    cbAntialias = createCheck(this, "Antialiasing");
    cbRender = createCheck(this, "Render Quality");
}
 
Example 3
Source File: MultiGradientTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private ControlsPanel() {
    cmbPaint = createCombo(this, paintType);
    cmbPaint.setSelectedIndex(1);
    cmbCycle = createCombo(this, cycleMethod);
    cmbSpace = createCombo(this, colorSpace);
    cmbShape = createCombo(this, shapeType);
    cmbXform = createCombo(this, xformType);

    int max = COLORS.length;
    SpinnerNumberModel model = new SpinnerNumberModel(max, 2, max, 1);
    spinNumColors = new JSpinner(model);
    spinNumColors.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numColors = ((Integer)spinNumColors.getValue()).intValue();
            gradientPanel.updatePaint();
        }
    });
    add(spinNumColors);

    cbAntialias = createCheck(this, "Antialiasing");
    cbRender = createCheck(this, "Render Quality");
}
 
Example 4
Source File: MultiGradientTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private ControlsPanel() {
    cmbPaint = createCombo(this, paintType);
    cmbPaint.setSelectedIndex(1);
    cmbCycle = createCombo(this, cycleMethod);
    cmbSpace = createCombo(this, colorSpace);
    cmbShape = createCombo(this, shapeType);
    cmbXform = createCombo(this, xformType);

    int max = COLORS.length;
    SpinnerNumberModel model = new SpinnerNumberModel(max, 2, max, 1);
    spinNumColors = new JSpinner(model);
    spinNumColors.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numColors = ((Integer)spinNumColors.getValue()).intValue();
            gradientPanel.updatePaint();
        }
    });
    add(spinNumColors);

    cbAntialias = createCheck(this, "Antialiasing");
    cbRender = createCheck(this, "Render Quality");
}
 
Example 5
Source File: BiomeExporterDialog.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
private JSpinner createCoordinateSpinner() {
	JSpinner newSpinner = new JSpinner(new SpinnerNumberModel(0, -30000000, 30000000, 25));
	newSpinner.addChangeListener(e -> {
		renderPreview();
	});
	return newSpinner;
}
 
Example 6
Source File: ArrayInspector.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the GUI.
 */
protected void createGUI() {
  setSize(400, 300);
  setContentPane(new JPanel(new BorderLayout()));
  scrollpane = new JScrollPane(tables[0]);
  if(tables.length>1) {
    // create spinner
    SpinnerModel model = new SpinnerNumberModel(0, 0, tables.length-1, 1);
    spinner = new JSpinner(model);
    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner);
    editor.getTextField().setFont(tables[0].getFont());
    spinner.setEditor(editor);
    spinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        int i = ((Integer) spinner.getValue()).intValue();
        scrollpane.setViewportView(tables[i]);
      }

    });
    Dimension dim = spinner.getMinimumSize();
    spinner.setMaximumSize(dim);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);
    toolbar.add(new JLabel(" index ")); //$NON-NLS-1$
    toolbar.add(spinner);
    toolbar.add(Box.createHorizontalGlue());
    getContentPane().add(toolbar, BorderLayout.NORTH);
  } else {
    scrollpane.createHorizontalScrollBar();
    getContentPane().add(scrollpane, BorderLayout.CENTER);
  }
}
 
Example 7
Source File: CustomSettingsDialog.java    From swingsane with Apache License 2.0 5 votes vote down vote up
public SpinnerEditor(final JSpinner spinner, final OptionsOrderValuePair vp) {
  super(new JTextField());
  this.spinner = spinner;
  valuePair = vp;
  spinner.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent e) {
      updateOption(valuePair, spinner);
    }
  });
  setClickCountToStart(1);
}
 
Example 8
Source File: bug6463712.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 9
Source File: JMonthChooser.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * JMonthChooser constructor with month spinner parameter.
 * 
 * @param hasSpinner
 *            true, if the month chooser should have a spinner component
 */
public JMonthChooser(boolean hasSpinner) {
	super();
	setName("JMonthChooser");
	this.hasSpinner = hasSpinner;

	setLayout(new BorderLayout());

	comboBox = new JComboBox();
	comboBox.addItemListener(this);

	// comboBox.addPopupMenuListener(this);
	locale = Locale.getDefault();
	initNames();

	if (hasSpinner) {
		spinner = new JSpinner() {
			private static final long serialVersionUID = 1L;

			private JTextField textField = new JTextField();

			public Dimension getPreferredSize() {
				Dimension size = super.getPreferredSize();
				return new Dimension(size.width, textField
						.getPreferredSize().height);
			}
		};
		spinner.addChangeListener(this);
		spinner.setEditor(comboBox);
		comboBox.setBorder(new EmptyBorder(0, 0, 0, 0));
		updateUI();

		add(spinner, BorderLayout.WEST);
	} else {
		add(comboBox, BorderLayout.WEST);
	}

	initialized = true;
	setMonth(Calendar.getInstance().get(Calendar.MONTH));
}
 
Example 10
Source File: bug6463712.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 11
Source File: bug6463712.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 12
Source File: PasswordEchoPerChar.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public PasswordEchoPerChar() {
    super("Password echo per char");

    this.setLayout(new BorderLayout());
    final JPanel panel = new JPanel(new FlowLayout());
    this.add(panel, BorderLayout.CENTER);

    final JPasswordField jpf = new JPasswordField("sample");
    jpf.setColumns(20);
    panel.add(jpf);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JSpinner countSpinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 5, 1);
    countSpinner.setModel(model);
    countSpinner.addChangeListener((ChangeEvent e) -> {
        // set the amount of echo per character based on the current
        // value in the spinner
        SubstanceCortex.ComponentScope.setNumberOfPasswordEchoesPerCharacter(jpf,
                (int) countSpinner.getValue());
        jpf.repaint();
    });

    controls.add(new JLabel("Echo per char"));
    controls.add(countSpinner);
    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400, 200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 13
Source File: JValueInteger.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
JValueInteger(Preferences _node, String _key) {
  super(_node, _key, ExtPreferences.TYPE_INT);

  int val = node.getInt(key, 0);
  /*
  text = new JTextField("" + val, 20) {{
    addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          try {
            node.putInt(key, Integer.parseInt(text.getText()));
            setErr(null);
          } catch (Exception e) {
            setErr(e.getClass().getName() + " " + e.getMessage());
          }
        }
      });
  }};
  */

  model = 
    new SpinnerNumberModel(new Integer(val),
                           new Integer(Integer.MIN_VALUE),
                           new Integer(Integer.MAX_VALUE),
                           new Integer(1));
  
  spinner = new JSpinner(model);
  spinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent ev) {
        try {
          node.putInt(key, model.getNumber().intValue());
          setErr(null);
        } catch (Exception e) {
          setErr(e.getClass().getName() + " " + e.getMessage());
        }
          }
    });
  add(spinner, BorderLayout.CENTER);
}
 
Example 14
Source File: TimeSeriesMatrixTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void initUI() {
    SnapApp.getDefault().getSelectionSupport(ProductSceneView.class).addHandler(sceneViewListener);

    dateLabel = new JLabel(String.format(DATE_PREFIX + " %s", getStartDateString()));
    matrixSizeSpinner = new JSpinner(new SpinnerNumberModel(MATRIX_DEFAULT_VALUE,
                                                            MATRIX_MINIMUM, MATRIX_MAXIMUM,
                                                            MATRIX_STEP_SIZE));
    final JComponent editor = matrixSizeSpinner.getEditor();
    if (editor instanceof JSpinner.DefaultEditor) {
        ((JSpinner.DefaultEditor) editor).getTextField().setEditable(false);
    }
    matrixSizeSpinner.addChangeListener(e -> matrixModel.setMatrixSize((Integer) matrixSizeSpinner.getModel().getValue()));

    final TableLayout tableLayout = new TableLayout(2);
    tableLayout.setTablePadding(4, 4);
    tableLayout.setTableFill(TableLayout.Fill.BOTH);
    tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
    tableLayout.setTableWeightX(0.0);
    tableLayout.setTableWeightY(0.0);
    tableLayout.setColumnWeightX(0, 1.0);
    tableLayout.setRowWeightY(1, 1.0);
    tableLayout.setCellColspan(0, 0, 2);

    setLayout(tableLayout);
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JPanel buttonPanel = createButtonPanel();
    JPanel tablePanel = createTablePanel();
    add(dateLabel);
    add(tablePanel);
    add(buttonPanel);

    setCurrentView(SnapApp.getDefault().getSelectedProductSceneView());
    setDisplayName(Bundle.CTL_TimeSeriesMatrixTopComponentName());
}
 
Example 15
Source File: bug6463712.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 16
Source File: EntityBoard.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Convenient method to allocate an entity-based spinner
 *
 * @param index the underlying entity index
 * @return the spinner built
 */
private JSpinner makeIdSpinner (EntityIndex<E> index)
{
    JSpinner spinner = new JSpinner(new SpinnerIdModel<>(index));
    spinner.setValue(0); // Initial value before listener is set!
    spinner.addChangeListener(this);
    spinner.setLocale(Locale.ENGLISH);
    SpinnerUtil.setRightAlignment(spinner);
    SpinnerUtil.setEditable(spinner, true);

    return spinner;
}
 
Example 17
Source File: bug6463712.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 18
Source File: bug6463712.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 19
Source File: TestFrame.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private Container createContentPanel() {
    final JPanel panel = new JPanel() {

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            model.paint((Graphics2D) g, this.getBounds());
        }
    };

    final JPanel res = new JPanel(new BorderLayout());
    res.add(panel, BorderLayout.CENTER);
    final JSpinner slider = new JSpinner(
            new SpinnerNumberModel(4, 2, 8, 1) {

            });
    res.add(slider, BorderLayout.SOUTH);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            model.setCount(((Number) slider.getValue()).intValue());
            TestFrame.this.repaint();
        }

    });
    return res;
}
 
Example 20
Source File: TableCellUtilities.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private SpinnerEditor(JSpinner spinner)
{
	this.spinner = spinner;
	spinner.addChangeListener(this);
}