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

The following examples show how to use javax.swing.JSpinner#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: ScriptInspector.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void addToSet(JSpinner spinner)
{
	int script = (Integer) spinner.getValue();
	Set<Integer> set = getSet();
	set.add(script);
	refreshList();
	spinner.setValue(0);
}
 
Example 2
Source File: GenericPanelBuilder.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
private static JComponent createSpinner(final ConfigAttribute attribute) {
	final JSpinner spinner = new JSpinner(createModel(attribute));
	JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner);
	editor.getTextField().setHorizontalAlignment(JFormattedTextField.LEFT);
	editor.getFormat().setGroupingUsed(false);
	spinner.setEditor(editor);
	spinner.setValue(attribute.getValue());

	spinner.addChangeListener(new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			attribute.setValue(parseAs(unwrap(attribute.getType()),
					String.valueOf(spinner.getValue())));
		}
	});
	return spinner;
}
 
Example 3
Source File: AnimationObjectEditor.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void initSourceDestMotion(Motion m, JSpinner start, JCheckBox check, JSpinner dest, JComboBox motionType) {
    if(m == null) {
        check.setSelected(false);
        start.setEnabled(false);
        dest.setEnabled(false);
        return;
    }
    start.setValue(m.getSourceValue());
    //if(m.getSourceValue() != m.getDestinationValue()) {
        check.setSelected(true);
        motionType.setEnabled(true);
        dest.setEnabled(true);
        start.setEnabled(true);
    //} else {
    //    check.setSelected(false);
    //}
    motionType.setSelectedIndex(AnimationAccessor.getMotionType(m) - 1);
    dest.setValue(m.getDestinationValue());
}
 
Example 4
Source File: ScriptInspector.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void addToSet(JSpinner spinner)
{
	int script = (Integer) spinner.getValue();
	Set<Integer> set = getSet();
	set.add(script);
	refreshList();
	spinner.setValue(0);
}
 
Example 5
Source File: ComparePanel.java    From mvisc with GNU General Public License v3.0 5 votes vote down vote up
public ComparePanel()
{
	dateSpinner = new JSpinner( new SpinnerDateModel() );
	JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(dateSpinner, "dd.MM.yyyy");
	dateSpinner.setEditor(dateEditor);
	dateSpinner.setValue(new Date()); 
	timeSpinner = new JSpinner( new SpinnerDateModel() );
	JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
	timeSpinner.setEditor(timeEditor);
	timeSpinner.setValue(new Date()); 
	
}
 
Example 6
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 7
Source File: ComponentController.java    From swingsane with Apache License 2.0 5 votes vote down vote up
private void updatePagesToScan(Integer pagesToScan) {
  JSpinner pagesToScanSpinner = components.getPagesToScanSpinner();
  if (pagesToScan == null) {
    pagesToScanSpinner.setEnabled(false);
  } else {
    pagesToScanSpinner.setEnabled(!(components.getBatchScanCheckBox().isSelected()));
    pagesToScanSpinner.setValue(pagesToScan);
  }
}
 
Example 8
Source File: AddAndScaleMultiImage.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void updateHeight(JSpinner source, JSpinner dest) {
    if(preserveAspectRatio.isSelected() && !lock) {
        lock = true;
        float width = get(source);
        float height = width / aspect;
        dest.setValue(new Integer((int)height));
        lock = false;
    }
}
 
Example 9
Source File: AddAndScaleMultiImage.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void updateWidth(JSpinner source, JSpinner dest) {
    if(preserveAspectRatio.isSelected() && !lock) {
        lock = true;
        float height = get(source);
        float width = height *  aspect;
        dest.setValue(new Integer((int)width));
        lock = false;
    }
}
 
Example 10
Source File: PreferencesDialog.java    From petscii-bbs with Mozilla Public License 2.0 4 votes vote down vote up
public PreferencesDialog(JFrame parent, Preferences preferences,
                         DisplaySettings settings) {
  
  super(parent, "Preferences...", true);
  this.preferences = preferences;
  this.settings = settings;
  
  // Control panel
  GridLayout grid = new GridLayout(5, 2);
  grid.setVgap(3);
  grid.setHgap(3);
  
  JPanel mainpanel = new JPanel(grid);
  
  JLabel stdfontLabel = new JLabel("Size of standard font: ");
  mainpanel.add(stdfontLabel);
  stdfontSpinner = new JSpinner();
  stdfontSpinner.setValue(settings.getStdFontSize());
  mainpanel.add(stdfontSpinner);

  JLabel fixedfontLabel = new JLabel("Size of fixed font: ");
  mainpanel.add(fixedfontLabel);    
  fixedfontSpinner = new JSpinner();
  fixedfontSpinner.setValue(settings.getFixedFontSize());
  mainpanel.add(fixedfontSpinner);
  
  JLabel backgroundLabel = new JLabel("Default background: ");
  mainpanel.add(backgroundLabel);
  backgroundCB = new JComboBox(colors);
  mainpanel.add(backgroundCB);
  preselect(backgroundCB, settings.getDefaultBackground());
  
  JLabel foregroundLabel = new JLabel("Default foreground: ");
  mainpanel.add(foregroundLabel);
  foregroundCB = new JComboBox(colors);
  mainpanel.add(foregroundCB);
  preselect(foregroundCB, settings.getDefaultForeground());

  JLabel antialiasLabel = new JLabel("Antialiased text: ");
  mainpanel.add(antialiasLabel);
  antialiasCB = new JCheckBox();
  antialiasCB.setSelected(settings.getAntialias());
  mainpanel.add(antialiasCB);
  
  // Button panel
  Box lowpanel = new Box(BoxLayout.Y_AXIS);
  lowpanel.add(new JSeparator());
  JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  lowpanel.add(buttonpanel);
  
  JButton okbutton = new JButton("Ok");
  JButton cancelbutton = new JButton("Cancel");
  getRootPane().setDefaultButton(okbutton);
  buttonpanel.add(okbutton);
  buttonpanel.add(cancelbutton);
  okbutton.addActionListener(this);
  cancelbutton.addActionListener(this);
  
  getContentPane().add(mainpanel, BorderLayout.NORTH);
  getContentPane().add(
      new JLabel("<html><body><i>(Note: Changes only take effect after a " +
                 "restart)</i></body></html>"),
                 BorderLayout.CENTER);
  getContentPane().add(lowpanel, BorderLayout.SOUTH);
  
  Border border = BorderFactory.createEmptyBorder(5, 5, 5, 3);
  ((JPanel) getContentPane()).setBorder(border);
  ((BorderLayout) getContentPane().getLayout()).setVgap(5);

  pack();
  
}
 
Example 11
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void setupInstance(JSpinner instance) {
    super.setupInstance(instance);
    
    if (value != null) instance.setValue(value);
}
 
Example 12
Source File: JComponentBuilders.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected void setupInstance(JSpinner instance) {
    super.setupInstance(instance);
    
    if (value != null) instance.setValue(value);
}
 
Example 13
Source File: MainGui.java    From LambdaAttack with MIT License 4 votes vote down vote up
private JPanel setTopPane() {
    JPanel topPanel = new JPanel();
    topPanel.add(new JLabel("Host: "));
    JTextField hostInput = new JTextField("127.0.0.1");
    topPanel.add(hostInput);

    topPanel.add(new JLabel("Port: "));
    JTextField portInput = new JTextField("25565");
    topPanel.add(portInput);

    topPanel.add(new JLabel("Join delay (ms): "));
    JSpinner delay = new JSpinner();
    delay.setValue(1000);
    topPanel.add(delay);

    topPanel.add(new JLabel("Auto Register: "));
    JCheckBox autoRegister = new JCheckBox();
    topPanel.add(autoRegister);

    topPanel.add(new JLabel("Amount: "));
    JSpinner amount = new JSpinner();
    amount.setValue(20);
    topPanel.add(amount);

    topPanel.add(new JLabel("NameFormat: "));
    JTextField nameFormat = new JTextField("Bot-%d");
    topPanel.add(nameFormat);

    JComboBox<String> versionBox = new JComboBox<>();
    Arrays.stream(GameVersion.values())
            .sorted(Comparator.reverseOrder())
            .map(GameVersion::getVersion)
            .forEach(versionBox::addItem);

    topPanel.add(versionBox);

    JButton startButton = new JButton("Start");
    JButton stopButton = new JButton("Stop");
    topPanel.add(startButton);
    topPanel.add(stopButton);

    JButton loadNames = new JButton("Load Names");
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("", "txt"));
    loadNames.addActionListener(new LoadNamesListener(botManager, frame, fileChooser));

    topPanel.add(loadNames);

    JButton loadProxies = new JButton("Load proxies");

    loadProxies.addActionListener(new LoadProxiesListener(botManager, frame, fileChooser));

    topPanel.add(loadProxies);

    startButton.addActionListener((action) -> {
        // collect the options on the gui thread
        // for thread-safety
        Options options = new Options(
                hostInput.getText(),
                Integer.parseInt(portInput.getText()),
                (int) amount.getValue(),
                (int) delay.getValue(),
                nameFormat.getText(),
                GameVersion.findByName((String) versionBox.getSelectedItem()),
                autoRegister.isSelected());

        botManager.getThreadPool().submit(() -> {
            try {
                botManager.start(options);
            } catch (Exception ex) {
                LambdaAttack.getLogger().log(Level.INFO, ex.getMessage(), ex);
            }
        });
    });

    stopButton.addActionListener(action -> botManager.stop());
    return topPanel;
}
 
Example 14
Source File: PreferencesDialog.java    From gpx-animator with Apache License 2.0 4 votes vote down vote up
public PreferencesDialog(final JFrame owner) {
    super(owner, true);

    final ResourceBundle resourceBundle = Preferences.getResourceBundle();

    setTitle(resourceBundle.getString("ui.dialog.preferences.title"));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    final FileSelector tileCachePathSelector = new FileSelector(DIRECTORIES_ONLY) {
        private static final long serialVersionUID = 7372002778979993241L;
        @Override
        protected Type configure(final JFileChooser outputFileChooser) {
            return Type.OPEN;
        }
    };
    tileCachePathSelector.setToolTipText(resourceBundle.getString("ui.dialog.preferences.cachepath.tooltip"));

    final JSpinner tileCacheTimeLimitSpinner = new JSpinner();
    tileCacheTimeLimitSpinner.setToolTipText(resourceBundle.getString("ui.dialog.preferences.cachetimelimit.tooltip"));
    tileCacheTimeLimitSpinner.setModel(new DurationSpinnerModel());
    tileCacheTimeLimitSpinner.setEditor(new DurationEditor(tileCacheTimeLimitSpinner));

    final JPanel trackColorPanel = new JPanel(new BorderLayout());
    final JCheckBox trackColorRandom = new JCheckBox(resourceBundle.getString("ui.dialog.preferences.track.color.random"));
    final ColorSelector trackColorSelector = new ColorSelector();
    trackColorRandom.setSelected(Preferences.getTrackColorRandom());
    trackColorSelector.setColor(Preferences.getTrackColorDefault());
    trackColorSelector.setEnabled(!Preferences.getTrackColorRandom());
    trackColorRandom.addActionListener((event) -> trackColorSelector.setEnabled(!trackColorRandom.isSelected()));
    trackColorPanel.add(trackColorRandom, BorderLayout.LINE_START);
    trackColorPanel.add(trackColorSelector, BorderLayout.CENTER);


    final JButton cancelButton = new JButton(resourceBundle.getString("ui.dialog.preferences.button.cancel"));
    cancelButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        setVisible(false);
        dispose();
    }));

    final JButton saveButton = new JButton(resourceBundle.getString("ui.dialog.preferences.button.save"));
    saveButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        Preferences.setTileCacheDir(tileCachePathSelector.getFilename());
        Preferences.setTileCacheTimeLimit((Long) tileCacheTimeLimitSpinner.getValue());
        Preferences.setTrackColorRandom(trackColorRandom.isSelected());
        Preferences.setTrackColorDefault(trackColorSelector.getColor());
        setVisible(false);
        dispose();
    }));

    setContentPane(FormBuilder.create()
            .padding(new EmptyBorder(20, 20, 20, 20))
            .columns("right:p, 5dlu, fill:[200dlu, pref]") //NON-NLS
            .rows("p, 5dlu, p, 5dlu, p, 5dlu, p, 5dlu, p, 5dlu, p, 10dlu, p") //NON-NLS

            .addSeparator(resourceBundle.getString("ui.dialog.preferences.cache.separator")).xyw(1, 1, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.cachepath.label")).xy(1, 3)
            .add(tileCachePathSelector).xy(3, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.cachetimelimit.label")).xy(1, 5)
            .add(tileCacheTimeLimitSpinner).xy(3, 5)

            .addSeparator(resourceBundle.getString("ui.dialog.preferences.track")).xyw(1, 7, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.track.color")).xy(1, 9)
            .add(trackColorPanel).xy(3, 9)

            .addSeparator("").xyw(1, 11, 3)
            .addBar(cancelButton, saveButton).xyw(1, 13, 3, CellConstraints.RIGHT, CellConstraints.FILL)
            .build());

    tileCachePathSelector.setFilename(Preferences.getTileCacheDir());
    tileCacheTimeLimitSpinner.setValue(Preferences.getTileCacheTimeLimit());

    pack();
    setLocationRelativeTo(owner);
}