javax.swing.JSpinner Java Examples

The following examples show how to use javax.swing.JSpinner. 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: SpinnerRangeDouble.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor.
 */
public SpinnerRangeDouble(double defValue, double minValue, double maxValue, double incValue, int visibleChars) {
	super();
	this.defValue = defValue;
	this.minValue = minValue;
	this.maxValue = maxValue;
	this.incValue = incValue;

	Double def = new Double(defValue);
	Double min = new Double(minValue);
	Double max = new Double(maxValue);
	Double inc = new Double(incValue);
	model = new SpinnerNumberModel(def, min, max, inc);
	setModel(model);
	JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
	tf.setColumns(visibleChars);
}
 
Example #2
Source File: SpinnerUtil.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Workaround for a swing bug : when the user enters an illegal value, the
 * text is forced to the last value.
 *
 * @param spinner the spinner to update
 */
public static void fixIntegerList (final JSpinner spinner)
{
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) spinner.getEditor();

    final JFormattedTextField ftf = editor.getTextField();
    ftf.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterAction");
    ftf.getActionMap().put("enterAction", new AbstractAction()
                   {
                       @Override
                       public void actionPerformed (ActionEvent e)
                       {
                           try {
                               spinner.setValue(Integer.parseInt(ftf.getText()));
                           } catch (NumberFormatException ex) {
                               // Reset to last value
                               ftf.setText(ftf.getValue().toString());
                           }
                       }
                   });
}
 
Example #3
Source File: SpinnerRangeFloat.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor.
 */
public SpinnerRangeFloat(float defValue, float minValue, float maxValue, float incValue, String format) {
	super();
	this.defValue = defValue;
	this.minValue = minValue;
	this.maxValue = maxValue;
	this.incValue = incValue;

	Double def = new Double(defValue);
	Double min = new Double(minValue);
	Double max = new Double(maxValue);
	Double inc = new Double(incValue);
	this.model = new SpinnerNumberModel(def, min, max, inc);
	setModel(model);
	setEditor(new JSpinner.NumberEditor(this, format));
	JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
	tf.setColumns(7);
}
 
Example #4
Source File: TimeRangePanel.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    lblTime1 = new javax.swing.JLabel();
    spnTime1 = new javax.swing.JSpinner();
    spnTime2 = new javax.swing.JSpinner();

    setOpaque(false);

    lblTime1.setText(org.openide.util.NbBundle.getMessage(TimeRangePanel.class, "DateCriteriaPanel.lblDate1.text")); // NOI18N

    spnTime1.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1366083314466L), null, null, java.util.Calendar.HOUR));

    spnTime2.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), null, null, java.util.Calendar.HOUR));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(spnTime1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(lblTime1)
            .addGap(18, 18, 18)
            .addComponent(spnTime2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 30, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(0, 0, 0)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(spnTime1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblTime1)
                .addComponent(spnTime2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    );
}
 
Example #5
Source File: RemindersPanel.java    From javamoney-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new preferences panel.
 */
public
RemindersPanel()
{
  super(PreferencesKeys.REMINDERS);

  setSpinner(new JSpinner(new SpinnerNumberModel(0, 0, 21, 1)));

  createButtons();

  buildPanel();

  // Initialize the panel with the selected reminder.
  displayReminderInfo();

  // Prevent users from entering arbitrary data in the spinner.
  ((JSpinner.NumberEditor)getSpinner().getEditor()).getTextField().setEditable(false);

  // Add listeners.
  getChooser().addTreeSelectionListener(new SelectionHandler());
  getSpinner().addChangeListener(new ChangeHandler());
}
 
Example #6
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 #7
Source File: SimulationParameters.java    From High-Frequency-Data-Order-Book-Analyser with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates new form FileSelection
 */
public SimulationParameters() {
    initComponents();
    this.setResizable(false);
    this.setTitle("File Selection");
    fileReader = new FileRead();
    initialiseDateComboBox(fileReader);

    JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(SpinnerTime, "HH:mm:ss");
    DateFormatter formatter = (DateFormatter) timeEditor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false); // Make sure no invalid input is allowed
    SpinnerTime.setEditor(timeEditor);
    String StartTime = "08:30:00";
    Date time;
    try {
        time = new SimpleDateFormat("HH:mm:ss").parse(StartTime);
        SpinnerTime.setValue(time); // will only show the current time
    } catch (ParseException ex) {
        Logger.getLogger(SimulationParameters.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example #8
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 #9
Source File: CustomizerGeneral.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form CustomizerGeneral */
public CustomizerGeneral(CustomizerDataSupport custData) {
    this.custData = custData;        
    initComponents();

    JTextField serverPortTextField = ((JSpinner.NumberEditor) serverPortSpinner.getEditor()).getTextField();
    AccessibleContext ac = serverPortTextField.getAccessibleContext();
    ac.setAccessibleName(NbBundle.getMessage(CustomizerGeneral.class, "ASCN_ServerPort"));
    ac.setAccessibleDescription(NbBundle.getMessage(CustomizerGeneral.class, "ASCD_ServerPort"));
    
    JTextField shutdownPortTextField = ((JSpinner.NumberEditor) shutdownPortSpinner.getEditor()).getTextField();
    ac = shutdownPortTextField.getAccessibleContext();
    ac.setAccessibleName(NbBundle.getMessage(CustomizerGeneral.class, "ASCN_ShutdownPort"));
    ac.setAccessibleDescription(NbBundle.getMessage(CustomizerGeneral.class, "ASCD_ShutdownPort"));
    
    // work-around for jspinner incorrect fonts
    Font font = usernameTextField.getFont();
    serverPortSpinner.setFont(font);
    shutdownPortSpinner.setFont(font);
}
 
Example #10
Source File: PlayerSearchField.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
@Override
public void reset() {
	super.reset();
	
	raceComboBox       .setSelectedIndex( 0 );
	leagueComboBox     .setSelectedIndex( 0 );
	matchResultComboBox.setSelectedIndex( 0 );
	
	minApmSpinner.getEditor().setBackground( null );
	restoreDefaultBackground( ( (JSpinner.NumberEditor) minApmSpinner.getEditor() ).getTextField() );
	minApmSpinner.setValue( MIN_VALID_APM );
	
	maxApmSpinner.getEditor().setBackground( null );
	restoreDefaultBackground( ( (JSpinner.NumberEditor) maxApmSpinner.getEditor() ).getTextField() );
	maxApmSpinner.setValue( MAX_VALID_APM );
}
 
Example #11
Source File: GlyphBoard.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * CallBack triggered by a change in one of the spinners.
 *
 * @param e the change event, this allows to retrieve the originating
 *          spinner
 */
@Override
public void stateChanged (ChangeEvent e)
{
    JSpinner spinner = (JSpinner) e.getSource();

    //  Nota: this method is automatically called whenever the spinner value
    //  is changed, including when a GLYPH selection notification is
    //  received leading to such selfUpdating. So the check.
    if (!selfUpdating) {
        // Notify the new glyph id
        getSelectionService()
                .publish(
                new GlyphIdEvent(
                this,
                SelectionHint.GLYPH_INIT,
                null,
                (Integer) spinner.getValue()));
    }
}
 
Example #12
Source File: SpinnerUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Assign the List model (for a list-based spinner)
 *
 * @param spinner the spinner to update
 * @param values  the model list values
 */
public static void setList (JSpinner spinner,
                            List<?> values)
{
    SpinnerModel model = spinner.getModel();

    if (model instanceof SpinnerListModel) {
        ((SpinnerListModel) model).setList(values);
    } else {
        throw new IllegalArgumentException("Spinner model is not a SpinnerListModel");
    }
}
 
Example #13
Source File: JSpinnerOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean checkComponent(Component comp) {
    if (comp instanceof JSpinner) {
        if (((JSpinner) comp).getValue() != null) {
            return (comparator.equals(((JSpinner) comp).getValue().toString(),
                    label));
        }
    }
    return false;
}
 
Example #14
Source File: SpinnerPreviousButtonPainter.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void paintButton(Graphics2D g, JComponent c, int width, int height) {
    boolean useToolBarColors = isInToolBar(c);
    Shape s;

    JSpinner spinner = (JSpinner) c.getParent();
    boolean editorFocused = false;
    JComponent editor = spinner.getEditor();
    if (editor instanceof DefaultEditor) {
        editorFocused = ((DefaultEditor)editor).getTextField().isFocusOwner();
    }
    if (focused || editorFocused) {
        s = createButtonShape(0, 0, width, height, CornerSize.OUTER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.OUTER_FOCUS, useToolBarColors));
        g.fill(s);

        s = createButtonShape(0, 0, width - 1, height - 1, CornerSize.INNER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.INNER_FOCUS, useToolBarColors));
        g.fill(s);
    }

    s = createButtonShape(0, 0, width - 2, height - 2, CornerSize.BORDER);
    g.setPaint(getSpinnerPrevBorderPaint(s, type));
    g.fill(s);

    s = createButtonShape(1, 1, width - 4, height - 4, CornerSize.INTERIOR);
    g.setPaint(getSpinnerPrevInteriorPaint(s, type));
    g.fill(s);

    s = shapeGenerator.createRectangle(1, 0, width - 4, 1);
    g.setPaint(getSpinnerPrevTopLinePaint(s, type));
    g.fill(s);
}
 
Example #15
Source File: JExtendedSpinner.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public JExtendedSpinner() {
    super();
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(UIManager.getFont("Label.font")); // NOI18N
    ((JSpinner.DefaultEditor) getEditor()).getTextField().addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(final java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                    processKeyEvent(e);
                }
            }
        });
    configureWheelListener();
}
 
Example #16
Source File: SpinnerUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Make the spinner text field editable, or not
 *
 * @param spinner the spinner to update
 * @param bool    true if editable, false otherwise
 */
public static void setEditable (JSpinner spinner,
                                boolean bool)
{
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) spinner.getEditor();
    editor.getTextField().setEditable(bool);
}
 
Example #17
Source File: JSpinnerOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSpinner.addChangeListener(ChangeListener)} through queue
 */
public void addChangeListener(final ChangeListener changeListener) {
    runMapping(new MapVoidAction("addChangeListener") {
        @Override
        public void map() {
            ((JSpinner) getSource()).addChangeListener(changeListener);
        }
    });
}
 
Example #18
Source File: InfoComponentFactoryV1.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Create an info component for the given {@link Accessor}
 * 
 * @param accessor The {@link Accessor}
 * @return The info component
 */
private JComponent createAccessorInfoComponent(Accessor accessor)
{
    JPanel panel = new JPanel(new BorderLayout());
    
    JPanel controlPanel = new JPanel(new FlowLayout());
    controlPanel.add(new JLabel("Elements per row:"));
    JSpinner numElementsPerRowSpinner = 
        new JSpinner(new SpinnerNumberModel(1, 0, (1<<20), 1));
    controlPanel.add(numElementsPerRowSpinner);
    
    panel.add(controlPanel, BorderLayout.NORTH);
    
    JPanel dataPanel = new JPanel(new BorderLayout());
    dataPanel.add(new JLabel("Accessor data:"), BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
    dataPanel.add(new JScrollPane(textArea));
    
    updateAccessorDataText(textArea, accessor, 1);

    panel.add(dataPanel, BorderLayout.CENTER);
    
    numElementsPerRowSpinner.addChangeListener(e -> 
    {
        Object valueObject = numElementsPerRowSpinner.getValue();
        Number valueNumber = (Number)valueObject;
        int elementsPerRow = valueNumber.intValue();
        if (elementsPerRow <= 0)
        {
            elementsPerRow = Integer.MAX_VALUE;
        }
        updateAccessorDataText(textArea, accessor, elementsPerRow);
    });

    return panel;
}
 
Example #19
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JLabel.class.getName())) {
        return new JLabelBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPanel.class.getName())) {
        return new JPanelBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToolBar.class.getName())) {
        return new JToolBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Box.Filler.class.getName())) {
        return new BoxFillerBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Box.class.getName())) {
        return new BoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JScrollBar.class.getName())) {
        return new JScrollBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToolBar.Separator.class.getName())) {
        return new JToolBarSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPopupMenu.Separator.class.getName())) {
        return new JPopupMenuSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSeparator.class.getName())) {
        return new JSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JProgressBar.class.getName())) {
        return new JProgressBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSlider.class.getName())) {
        return new JSliderBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSpinner.class.getName())) {
        return new JSpinnerBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPopupMenu.class.getName())) {
        return new JPopupMenuBuilder(instance, heap);
    }
    return null;
}
 
Example #20
Source File: DoubleProperty.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JComponent getEditorComponent() {
  final JSpinner field = new JSpinner(new SpinnerNumberModel(value, min, max, 1.0));

  // NB: Workaround for JSpinner default sizing algorithm when min/max values have very large
  // magnitudes
  // (see: https://implementsblog.com/2012/11/26/java-gotcha-jspinner-preferred-size/)
  final JComponent fieldEditor = field.getEditor();
  if (fieldEditor instanceof JSpinner.DefaultEditor) {
    ((JSpinner.DefaultEditor) fieldEditor).getTextField().setColumns(10);
  }

  field.addChangeListener(e -> value = (double) field.getValue());
  return field;
}
 
Example #21
Source File: PlanManager.java    From cropplanning with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void buildContentsPanel() {
   
   cmboPlanList = new JComboBox();
   cmboPlanList.setEditable(true);
   cmboPlanList.addActionListener(this);
   
   spnYear = new JSpinner();
   SpinnerDateModel spnMod = new SpinnerDateModel();
   spnMod.setCalendarField( Calendar.YEAR );
   spnYear.setModel( spnMod );
   spnYear.setEditor( new JSpinner.DateEditor( spnYear, "yyyy" ) );

   spnYear.setPreferredSize( new Dimension( 70, 
                                            spnYear.getPreferredSize().height ));
   tfldDesc = new JTextField( 20 );
   
   JPanel jplCont = new JPanel( new MigLayout( "gapy 0px!, insets 2px", "[align right][]") );
     
   jplCont.add( new JLabel( "Plan:" ) );
   jplCont.add( cmboPlanList, "wrap" );
   jplCont.add( new JLabel( "Year:" ) );
   jplCont.add( spnYear, "wrap" );
   jplCont.add( new JLabel( "Description:" ) );
   jplCont.add( tfldDesc, "wrap" );
   
   jplCont.setBorder( BorderFactory.createEmptyBorder( 10, 10, 0, 10));

   contentsPanelBuilt = true;
   add( jplCont );
   
}
 
Example #22
Source File: Spiral2DDemo.java    From pumpernickel with MIT License 5 votes vote down vote up
public Spiral2DDemo() {
	super(true, true, true);

	addSliderPopover(angleOffset, "\u00B0");
	
	Inspector inspector = new Inspector(configurationPanel);
	inspector.addRow(coilGapLabel, coilGap);
	inspector.addRow(coilsLabel, coils);
	inspector.addRow(angleOffsetLabel, angleOffset);
	inspector.addRow(coilOffsetLabel, coilOffset);
	inspector.addRow(null, clockwise);
	inspector.addRow(null, outward);
	outward.setToolTipText("This should produce no visual difference.");

	examplePanel.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.gridwidth = GridBagConstraints.REMAINDER;
	c.fill = GridBagConstraints.BOTH;
	c.weightx = 1;
	c.weighty = 1;
	examplePanel.add(preview, c);

	ChangeListener changeListener = new ChangeListener() {
		public void stateChanged(ChangeEvent e) {
			preview.repaint();
		}
	};
	outward.addChangeListener(changeListener);
	angleOffset.addChangeListener(changeListener);
	coilOffset.addChangeListener(changeListener);
	coilGap.addChangeListener(changeListener);
	coils.addChangeListener(changeListener);
	clockwise.addChangeListener(changeListener);

	coilGap.setEditor(new JSpinner.NumberEditor(coilGap, "#.00"));
	coils.setEditor(new JSpinner.NumberEditor(coils, "#.00"));
	coilOffset.setEditor(new JSpinner.NumberEditor(coilOffset, "0.00"));
}
 
Example #23
Source File: RDefaultEditor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public String getText() {
    if (component instanceof JSpinner.DefaultEditor) {
        String text = ((JSpinner.DefaultEditor) component).getTextField().getText();
        return text;
    }
    return null;
}
 
Example #24
Source File: BoxFillerInitializer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
WidthHeightPanel(boolean showWidth, boolean showHeight) {
    ResourceBundle bundle = NbBundle.getBundle(BoxFillerInitializer.class);
    JLabel widthLabel = new JLabel(bundle.getString("BoxFillerInitializer.width")); // NOI18N
    JLabel heightLabel = new JLabel(bundle.getString("BoxFillerInitializer.height")); // NOI18N
    widthField = new JSpinner(new SpinnerNumberModel());
    heightField = new JSpinner(new SpinnerNumberModel());
    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                .addComponent(widthLabel)
                .addComponent(heightLabel))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(widthField)
                .addComponent(heightField))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(widthLabel)
                .addComponent(widthField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(heightLabel)
                .addComponent(heightField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    widthLabel.setVisible(showWidth);
    heightLabel.setVisible(showHeight);
    widthField.setVisible(showWidth);
    heightField.setVisible(showHeight);
}
 
Example #25
Source File: CustomSettingsDialog.java    From swingsane with Apache License 2.0 5 votes vote down vote up
private void updateOption(OptionsOrderValuePair vp, Component component) {

    switch (vp.getSaneOptionType()) {

    case STRING:
      StringOption stringOption = scanner.getStringOptions().get(vp.getKey());
      if (component instanceof JTextField) {
        stringOption.setValue(((JTextField) component).getText());
      } else if (component instanceof JComboBox) {
        stringOption.setValue((String) ((JComboBox<?>) component).getSelectedItem());
      }
      break;

    case INTEGER:
      IntegerOption integerOptions = scanner.getIntegerOptions().get(vp.getKey());
      integerOptions.setValue((Integer) ((JSpinner) component).getValue());
      break;

    case BOOLEAN:
      BooleanOption booleanOptions = scanner.getBooleanOptions().get(vp.getKey());
      booleanOptions.setValue(((JCheckBox) component).isSelected());
      break;

    case FIXED:
      FixedOption fixedOptions = scanner.getFixedOptions().get(vp.getKey());
      fixedOptions.setValue((Double) ((JSpinner) component).getValue());
      break;

    case BUTTON:
      break;

    case GROUP:
      break;

    default:
      break;

    }

  }
 
Example #26
Source File: JExtendedSpinner.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setModel(SpinnerModel model) {
    Font font = ((JSpinner.DefaultEditor) getEditor()).getTextField().getFont();
    String accessibleName = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().getAccessibleName();
    String accessibleDescription = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
                                    .getAccessibleDescription();
    super.setModel(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(font);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().setAccessibleName(accessibleName);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
     .setAccessibleDescription(accessibleDescription);
}
 
Example #27
Source File: JComponentBuilders.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JLabel.class.getName())) {
        return new JLabelBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPanel.class.getName())) {
        return new JPanelBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToolBar.class.getName())) {
        return new JToolBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Box.Filler.class.getName())) {
        return new BoxFillerBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Box.class.getName())) {
        return new BoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JScrollBar.class.getName())) {
        return new JScrollBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToolBar.Separator.class.getName())) {
        return new JToolBarSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPopupMenu.Separator.class.getName())) {
        return new JPopupMenuSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSeparator.class.getName())) {
        return new JSeparatorBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JProgressBar.class.getName())) {
        return new JProgressBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSlider.class.getName())) {
        return new JSliderBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JSpinner.class.getName())) {
        return new JSpinnerBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JPopupMenu.class.getName())) {
        return new JPopupMenuBuilder(instance, heap);
    }
    return null;
}
 
Example #28
Source File: bug8008657.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void createNumberSpinner() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.YEAR, -1);
    calendar.add(Calendar.YEAR, 1);
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
            currentYear - 1, //min
            currentYear + 2, //max
            1);                //step
    spinner = new JSpinner();
    spinner.setModel(yearModel);
}
 
Example #29
Source File: NoiseSettingsEditor.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates new form NoiseSettingsEditor
 */
public NoiseSettingsEditor() {
    initComponents();

    JSpinner.NumberEditor scaleEditor = new JSpinner.NumberEditor(spinnerScale, "0");
    scaleEditor.getTextField().setColumns(3);
    spinnerScale.setEditor(scaleEditor);
}
 
Example #30
Source File: SkillInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void releaseMouse(JSpinner jSpinner)
{
	IntStream.range(0, jSpinner.getComponentCount())
	         .mapToObj(jSpinner::getComponent)
	         .filter(comp -> comp instanceof JButton)
	         .forEach(this::releaseMouse);
}