Java Code Examples for javax.swing.SpinnerNumberModel#setValue()

The following examples show how to use javax.swing.SpinnerNumberModel#setValue() . 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: KnownSaneOptions.java    From swingsane with Apache License 2.0 6 votes vote down vote up
public static SpinnerModel getBlackThresholdModel(Scanner scanner) {
  SpinnerNumberModel blackThresholdModel = new SpinnerNumberModel(0, MIN_BLACK_THRESHOLD,
      MAX_BLACK_THRESHOLD, 1);

  HashMap<String, FixedOption> fixedOptions = scanner.getFixedOptions();

  FixedOption fixedOption = fixedOptions.get(SANE_NAME_THRESHOLD);

  if (fixedOption == null) {
    return null;
  }

  Constraints constraints = fixedOption.getConstraints();
  Integer maxInt = constraints.getMaximumInteger();
  Integer minInt = constraints.getMinimumInteger();

  blackThresholdModel.setMaximum(maxInt);
  blackThresholdModel.setMinimum(minInt);
  blackThresholdModel.setStepSize(constraints.getQuantumInteger());

  blackThresholdModel.setValue(fixedOption.getValue());

  return blackThresholdModel;
}
 
Example 2
Source File: GUIControls.java    From the-one with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Changes the zoom level
 * @param delta How much to change the current level (can be negative or
 * positive)
 */
public void changeZoom(int delta) {
	SpinnerNumberModel model =
		(SpinnerNumberModel)this.zoomSelector.getModel();
	double curZoom = model.getNumber().doubleValue();
	Number newValue = new Double(curZoom + model.getStepSize().
			doubleValue() * delta * curZoom * 100);

	if (newValue.doubleValue() < ZOOM_MIN) {
		newValue = ZOOM_MIN;
	} else if (newValue.doubleValue() > ZOOM_MAX) {
		newValue = ZOOM_MAX;
	}

	model.setValue(newValue);
	this.updateZoomScale(true);
}
 
Example 3
Source File: bug6463712.java    From TencentKona-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 4
Source File: frmControl.java    From sourcerabbit-gcode-sender with GNU General Public License v2.0 5 votes vote down vote up
public frmControl()
{
    fInstance = this;
    initComponents();

    // Set form in middle of screen
    Position2D pos = UITools.getPositionForFormToOpenInMiddleOfScreen(this.getSize().width, this.getSize().height);
    this.setLocation((int) pos.getX(), (int) pos.getY());

    InitEvents();
    InitUIThreads();

    this.setTitle("SourceRabbit GCode Sender (Version " + SettingsManager.getAppVersion() + ")");
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("Images/SourceRabbitIcon.png")));

    this.jCheckBoxEnableGCodeLog.setSelected(SettingsManager.getIsGCodeLogEnabled());
    this.jCheckBoxEnableKeyboardJogging.setSelected(SettingsManager.getIsKeyboardJoggingEnabled());

    InitMacroButtons();

    InitKeyListener();

    // Fix jSpinnerStep to work with system decimal point
    jSpinnerStep.setEditor(new JSpinner.NumberEditor(jSpinnerStep, "##.###"));
    SpinnerNumberModel spinnerModel = (SpinnerNumberModel) jSpinnerStep.getModel();
    spinnerModel.setStepSize(.001);
    spinnerModel.setValue(1.000);
    spinnerModel.setMinimum(0.001);
    jSpinnerStep.setModel(spinnerModel);
    UITools.FixSpinnerToWorkWithSystemDecimalPoint(jSpinnerStep);
}
 
Example 5
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 6
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 7
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 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: 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 10
Source File: bug6463712.java    From hottub 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 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 12
Source File: bug6463712.java    From openjdk-jdk9 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 13
Source File: NegotiationDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Update this panel.
 *
 * @param dt The {@code DiplomaticTrade} to update with.
 */
public void update(DiplomaticTrade dt) {
    int gold = dt.getGoldGivenBy(source);
    if (gold >= 0) {
        SpinnerNumberModel model
                = (SpinnerNumberModel)spinner.getModel();
        model.setValue(gold);
    }
}
 
Example 14
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 15
Source File: bug6463712.java    From openjdk-jdk8u 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: 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 17
Source File: bug6463712.java    From dragonwell8_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: EditSettlementDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create an EditSettlementDialog.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param is The {@code IndianSettlement} to edit.
 */
public EditSettlementDialog(FreeColClient freeColClient, JFrame frame,
                            final IndianSettlement is) {
    super(freeColClient, frame);

    this.is = is;

    this.name = new JTextField(is.getName(), 30);

    DefaultComboBoxModel<Nation> nationModel
        = new DefaultComboBoxModel<>();
    for (Nation n : getSpecification().getIndianNations()) {
        nationModel.addElement(n);
    }
    this.owner = new JComboBox<>(nationModel);
    this.owner.setSelectedItem(is.getOwner().getNation());
    this.owner.addItemListener(this);
    this.owner.setRenderer(new FreeColComboBoxRenderer<Nation>());

    this.capital = new JCheckBox();
    this.capital.setSelected(is.isCapital());

    this.skill = new JComboBox<>(getSkillModel());
    this.skill.setSelectedItem(is.getLearnableSkill());
    this.skill.setRenderer(new FreeColComboBoxRenderer<UnitType>());

    int unitCount = is.getUnitCount();
    SpinnerNumberModel spinnerModel
        = new SpinnerNumberModel(unitCount, 1, 20, 1);
    this.units = new JSpinner(spinnerModel);
    spinnerModel.setValue(unitCount);

    JPanel panel = new MigPanel(new MigLayout("wrap 2, gapx 20"));
    panel.add(Utility.localizedLabel("name"));
    panel.add(this.name);
    panel.add(Utility.localizedLabel("nation"));
    panel.add(this.owner);
    panel.add(Utility.localizedLabel("capital"));
    panel.add(this.capital);
    panel.add(Utility.localizedLabel("skillTaught"));
    panel.add(this.skill);
    panel.add(Utility.localizedLabel("units"));
    panel.add(this.units);

    List<ChoiceItem<IndianSettlement>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"), is).okOption());
    c.add(new ChoiceItem<>(Messages.message("editSettlementDialog.removeSettlement"), null));
    c.add(new ChoiceItem<>(Messages.message("cancel"),
                           (IndianSettlement)null).cancelOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, true, panel, new ImageIcon(
        getImageLibrary().getSmallSettlementImage(is)), c);
}
 
Example 19
Source File: SpinnerUtils.java    From WorldPainter with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Set the maximum of a number spinner model to a new value, adjusting the
 * current value first if necessary.
 * 
 * @param model The model of which to set the maximum.
 * @param newMaximum The value to set the maximum to. Must be a
 * {@link Number}.
 */
public static void setMaximum(SpinnerNumberModel model, Comparable<?> newMaximum) {
    if (((Number) model.getValue()).doubleValue() > ((Number) newMaximum).doubleValue()) {
        model.setValue(newMaximum);
    }
    model.setMaximum(newMaximum);
}