javax.swing.JSpinner#DefaultEditor ( )源码实例Demo

下面列出了javax.swing.JSpinner#DefaultEditor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: audiveris   文件: SpinnerUtil.java
/**
 * 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());
                           }
                       }
                   });
}
 
源代码2 项目: Course_Generator   文件: CgSpinnerDouble.java
public CgSpinnerDouble(double start, double min, double max, double step) {
	super();
	this.min = min;
	this.max = max;
	this.step = step;

	model = new SpinnerNumberModel(start, // initial value
			min, // min
			max, // max
			step);

	this.setModel(model);

	addMouseWheelListener(new MouseWheelListener() {
		public void mouseWheelMoved(MouseWheelEvent mwe) {
			MouseWheelAction(mwe.getWheelRotation());
		}
	});

	// Center
	JSpinner.DefaultEditor spinnerEditor = (JSpinner.DefaultEditor) this.getEditor();
	spinnerEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
}
 
源代码3 项目: Course_Generator   文件: CgSpinner.java
public CgSpinner(int start, int min, int max, int step) {
	super();
	this.min = min;
	this.max = max;
	this.step = step;

	model = new SpinnerNumberModel(start, // initial value
			min, // min
			max, // max
			step); // step
	setModel(model);

	addMouseWheelListener(new MouseWheelListener() {
		public void mouseWheelMoved(MouseWheelEvent mwe) {
			MouseWheelAction(mwe.getWheelRotation());
		}
	});

	// Center
	JSpinner.DefaultEditor spinnerEditor = (JSpinner.DefaultEditor) this.getEditor();
	spinnerEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
}
 
源代码4 项目: libreveris   文件: SpinnerUtil.java
/**
 * 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 (Exception ex) {
                // Reset to last value
                ftf.setText(ftf.getValue().toString());
            }
        }
    });
}
 
源代码5 项目: FlatLaf   文件: FlatBorder.java
protected boolean isFocused( Component c ) {
	if( c instanceof JScrollPane ) {
		JViewport viewport = ((JScrollPane)c).getViewport();
		Component view = (viewport != null) ? viewport.getView() : null;
		if( view != null ) {
			if( FlatUIUtils.isPermanentFocusOwner( view ) )
				return true;

			if( (view instanceof JTable && ((JTable)view).isEditing()) ||
				(view instanceof JTree && ((JTree)view).isEditing()) )
			{
				Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
				if( focusOwner != null )
					return SwingUtilities.isDescendingFrom( focusOwner, view );
			}
		}
		return false;
	} else if( c instanceof JComboBox && ((JComboBox<?>)c).isEditable() ) {
		Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
		return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
	} else if( c instanceof JSpinner ) {
		if( FlatUIUtils.isPermanentFocusOwner( c ) )
			return true;

		JComponent editor = ((JSpinner)c).getEditor();
		if( editor instanceof JSpinner.DefaultEditor ) {
			JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
			if( textField != null )
				return FlatUIUtils.isPermanentFocusOwner( textField );
		}
		return false;
	} else
		return FlatUIUtils.isPermanentFocusOwner( c );
}
 
源代码6 项目: marathonv5   文件: JSpinnerJavaElement.java
private Component getEditor() {
    JComponent editorComponent = ((JSpinner) component).getEditor();
    if (editorComponent == null) {
        throw new JavaAgentException("Null value returned by getEditor() on spinner", null);
    }
    if (editorComponent instanceof JSpinner.DefaultEditor) {
        editorComponent = ((JSpinner.DefaultEditor) editorComponent).getTextField();
    }
    return editorComponent;
}
 
源代码7 项目: marathonv5   文件: RSpinner.java
private String getSpinnerText() {
    JComponent editor = ((JSpinner) component).getEditor();

    if (editor == null) {
    } else {
        RComponentFactory finder = new RComponentFactory(omapConfig);
        if (editor instanceof JSpinner.DefaultEditor) {
            RComponent rComponent = finder.findRawRComponent(editor, null, recorder);
            return rComponent.getText();
        }
    }
    return null;
}
 
源代码8 项目: marathonv5   文件: RDefaultEditor.java
@Override
public String getText() {
    if (component instanceof JSpinner.DefaultEditor) {
        String text = ((JSpinner.DefaultEditor) component).getTextField().getText();
        return text;
    }
    return null;
}
 
源代码9 项目: audiveris   文件: IntegerListSpinner.java
/**
 * Creates a new IntegerListSpinner object.
 */
public IntegerListSpinner ()
{
    setModel(new SpinnerListModel());

    // Right alignment
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) getEditor();
    editor.getTextField().setHorizontalAlignment(JTextField.RIGHT);
}
 
源代码10 项目: audiveris   文件: SpinnerUtil.java
/**
 * 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);
}
 
源代码11 项目: audiveris   文件: SpinnerUtil.java
/**
 * Align the spinner display to the right
 *
 * @param spinner the spinner to update
 */
public static void setRightAlignment (JSpinner spinner)
{
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) spinner.getEditor();
    editor.getTextField().setHorizontalAlignment(JTextField.RIGHT);
}
 
源代码12 项目: triplea   文件: DoubleProperty.java
@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;
}
 
源代码13 项目: stendhal   文件: DropAmountChooser.java
/**
 * Get the editable text field component of the spinner.
 *
 * @return text field
 */
private JTextField getTextField() {
	// There really seems to be no simpler way to do this
	JComponent editor = spinner.getEditor();
	if (editor instanceof JSpinner.DefaultEditor) {
		return ((JSpinner.DefaultEditor) editor).getTextField();
	} else {
		Logger.getLogger(DropAmountChooser.class).error("Unknown editor type", new Throwable());
		// This will not work, but at least it won't crash the client
		return new JTextField();
	}
}
 
源代码14 项目: libreveris   文件: IntegerListSpinner.java
/**
 * Creates a new IntegerListSpinner object.
 */
public IntegerListSpinner ()
{
    setModel(new SpinnerListModel());

    // Right alignment
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) getEditor();
    editor.getTextField()
            .setHorizontalAlignment(JTextField.RIGHT);
}
 
源代码15 项目: libreveris   文件: SpinnerUtil.java
/**
 * 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);
}
 
源代码16 项目: libreveris   文件: SpinnerUtil.java
/**
 * Align the spinner display to the right
 *
 * @param spinner the spinner to update
 */
public static void setRightAlignment (JSpinner spinner)
{
    JSpinner.DefaultEditor editor;
    editor = (JSpinner.DefaultEditor) spinner.getEditor();
    editor.getTextField()
            .setHorizontalAlignment(JTextField.RIGHT);
}
 
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());
}
 
源代码18 项目: FlatLaf   文件: FlatSpinnerUI.java
private static JTextField getEditorTextField( JComponent editor ) {
	return editor instanceof JSpinner.DefaultEditor
		? ((JSpinner.DefaultEditor)editor).getTextField()
		: null;
}