@Override public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB){ try { ((JSpinner)editorComponent).commitEdit(); } catch (ParseException e1) { DefaultEditor de = (DefaultEditor) ((JSpinner)editorComponent).getEditor(); String text = de.getTextField().getText(); if(text.matches("^\\d+(\\.\\d*)?")){ ((JSpinner)editorComponent).setValue(Float.parseFloat(text)); }else{ System.err.println("Invalid input - ignoring"); } } } super.keyPressed(e); }
public static void reset() { add(Component.class, JavaElement.class); add(JList.class, JListJavaElement.class); add(JTabbedPane.class, JTabbedPaneJavaElement.class); add(JComboBox.class, JComboBoxJavaElement.class); add(JTable.class, JTableJavaElement.class); add(JTableHeader.class, JTableHeaderJavaElement.class); add(JTree.class, JTreeJavaElement.class); add(JToggleButton.class, JToggleButtonJavaElement.class); add(JSpinner.class, JSpinnerJavaElement.class); add(JProgressBar.class, JProgressBarJavaElement.class); add(JSplitPane.class, JSplitPaneJavaElement.class); add(JTextComponent.class, JTextComponentJavaElement.class); add(EditorContainer.class, JTreeEditingContainerJavaElement.class); add(JEditorPane.class, JEditorPaneJavaElement.class); add(JMenuItem.class, JMenuItemJavaElement.class); add(JSlider.class, JSliderJavaElement.class); add(JSpinner.class, JSpinnerJavaElement.class); add(DefaultEditor.class, DefaultEditorJavaElement.class); add(JColorChooser.class, JColorChooserJavaElement.class); add(JFileChooser.class, JFileChooserJavaElement.class); }
public static void reset() { entries.clear(); add(Component.class, RUnknownComponent.class); add(Window.class, RWindow.class); add(JTable.class, RTable.class); add(JTableHeader.class, RTableHeader.class); add(AbstractButton.class, RAbstractButton.class); add(JToggleButton.class, RToggleButton.class); add(JComboBox.class, RComboBox.class); add(JTextComponent.class, RTextComponent.class); add(JTree.class, RTree.class); add(JList.class, RList.class); add(JTabbedPane.class, RTabbedPane.class); add(JMenuItem.class, RMenuItem.class); add(JSlider.class, RSlider.class); add(JProgressBar.class, RProgressBar.class); add(JSpinner.class, RSpinner.class); add(DefaultEditor.class, RDefaultEditor.class); add(JColorChooser.class, RColorChooser.class); add(JSplitPane.class, RSplitPane.class); add(BasicSplitPaneDivider.class, RSplitPane.class); add(JFileChooser.class, RFileChooser.class); add(JEditorPane.class, REditorPane.class); add(JLabel.class, RLabel.class); add(JScrollBar.class, RIgnoreComponent.class); }
void buildPanel() { int count = this.model.getCount(); this.spinners[4].setVisible(count > 4); for (int i = 0; i < count; i++) { String text = this.model.getLabel(this, i); Object object = this.spinners[i].getLabel(); if (object instanceof JRadioButton) { JRadioButton button = (JRadioButton) object; button.setText(text); button.getAccessibleContext().setAccessibleDescription(text); } else if (object instanceof JLabel) { JLabel label = (JLabel) object; label.setText(text); } this.spinners[i].setRange(this.model.getMinimum(i), this.model.getMaximum(i)); this.spinners[i].setValue(this.values[i]); this.spinners[i].getSlider().getAccessibleContext().setAccessibleName(text); this.spinners[i].getSpinner().getAccessibleContext().setAccessibleName(text); DefaultEditor editor = (DefaultEditor) this.spinners[i].getSpinner().getEditor(); editor.getTextField().getAccessibleContext().setAccessibleName(text); this.spinners[i].getSlider().getAccessibleContext().setAccessibleDescription(text); this.spinners[i].getSpinner().getAccessibleContext().setAccessibleDescription(text); editor.getTextField().getAccessibleContext().setAccessibleDescription(text); } }
protected void fixupEditor(final JComponent editor) { if (!(editor instanceof DefaultEditor)) return; editor.setOpaque(false); editor.setInheritsPopupMenu(true); if (editor.getFont() instanceof UIResource) { editor.setFont(spinner.getFont()); } final JFormattedTextField editorTextField = ((DefaultEditor)editor).getTextField(); if (editorTextField.getFont() instanceof UIResource) { editorTextField.setFont(spinner.getFont()); } final InputMap spinnerInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); final InputMap editorInputMap = editorTextField.getInputMap(); final KeyStroke[] keys = spinnerInputMap.keys(); for (final KeyStroke k : keys) { editorInputMap.put(k, spinnerInputMap.get(k)); } }
protected void fixupEditor(final JComponent editor) { if (!(editor instanceof DefaultEditor)) { return; } editor.setOpaque(false); editor.setInheritsPopupMenu(true); if (editor.getFont() instanceof UIResource) { editor.setFont(new FontUIResource(spinner.getFont())); } final JFormattedTextField editorTextField = ((DefaultEditor) editor).getTextField(); if (editorTextField.getFont() instanceof UIResource) { editorTextField.setFont(new FontUIResource(spinner.getFont())); } final InputMap spinnerInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); final InputMap editorInputMap = editorTextField.getInputMap(); final KeyStroke[] keys = spinnerInputMap.keys(); for (final KeyStroke k : keys) { editorInputMap.put(k, spinnerInputMap.get(k)); } }
private static void testDefaultFont(final JFrame frame) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSpinner spinner = new JSpinner(); frame.add(spinner); frame.setSize(300, 100); frame.setVisible(true); final DefaultEditor editor = (DefaultEditor) spinner.getEditor(); final Font editorFont = editor.getTextField().getFont(); /* * Validate that the font of the text field is changed to the * font of JSpinner if the font of text field was not set by the * user. */ if (!(editorFont instanceof UIResource)) { throw new RuntimeException("Font must be UIResource"); } if (!editorFont.equals(spinner.getFont())) { throw new RuntimeException("Wrong FONT"); } }
protected JComponent createEditor() { JComponent editor = super.createEditor(); // 设置文本框属性 // set text frame info. if(editor instanceof DefaultEditor) { ((DefaultEditor)editor).getTextField().setBorder(null); ((DefaultEditor)editor).getTextField().setOpaque(false); ((DefaultEditor)editor).setOpaque(false); } return editor; }
/** * @param value * @param n * @param editor2 * @return */ protected DefaultEditor getEditor(final E value, final Number n, final JSpinner editor2) { if (Clazz.isDouble(n.getClass())) { return this.getDoubleEditor(); } else if (Clazz.isFloat(n.getClass())) { return this.getFloatEditor(); } else if (Clazz.isLong(n.getClass())) { return this.getLongEditor(); } else if (Clazz.isInteger(n.getClass())) { return this.getIntEditor(); } else if (Clazz.isShort(n.getClass())) { return this.getShortEditor(); } else if (Clazz.isByte(n.getClass())) { return this.getByteEditor(); } else { return this.getLongEditor(); } }
/** * Converts the given component to a <code>JTextComponent</code>. This can be a * simple cast if the component is already a text component, or an embedded component * (for example a JSpinner). * <p> * This method is protected, and can be overridden when necessary. * * @param component the component * @return a <code>JTextComponent</code>, or <code>null</code> */ protected JTextComponent getTextComponent( JComponent component ) { if( component instanceof JTextField ) { return (JTextField) component; } if( component instanceof JSpinner ) { JSpinner spinner = (JSpinner) component; if( spinner.getEditor() instanceof JSpinner.DefaultEditor ) { return ((DefaultEditor) spinner.getEditor()).getTextField(); } if( spinner.getEditor() instanceof JTextField ) { return (JTextField) spinner.getEditor(); } } return null; }
@Override public void run() { Project project = myLookup.lookup(Project.class); NbMavenProject mvnProject = project.getLookup().lookup( NbMavenProject.class); MavenProject mavenProject = mvnProject.getMavenProject(); File file = mavenProject.getFile(); FileObject pom = FileUtil .toFileObject(FileUtil.normalizeFile(file)); Utilities.performPOMModelOperations(pom, Collections.singletonList(this)); myJvmArgs.setText(jvmArgs); myStyle.setSelectedItem(style); myLogLevel.setSelectedItem(logLevel); if (threads == -1) { ((DefaultEditor) myThreads.getEditor()).getTextField().setText( ""); } else { myThreads.setValue(threads); } myDraft.setSelected(draft); }
SlidingSpinner(ColorPanel panel, JComponent label) { this.panel = panel; this.label = label; this.slider.addChangeListener(this); this.spinner.addChangeListener(this); DefaultEditor editor = (DefaultEditor) this.spinner.getEditor(); ValueFormatter.init(3, false, editor.getTextField()); editor.setFocusable(false); this.spinner.setFocusable(false); }
public void propertyChange(final PropertyChangeEvent e) { final String propertyName = e.getPropertyName(); final JSpinner spinner = (JSpinner)(e.getSource()); final SpinnerUI spinnerUI = spinner.getUI(); if (spinnerUI instanceof AquaSpinnerUI) { final AquaSpinnerUI ui = (AquaSpinnerUI)spinnerUI; if ("editor".equals(propertyName)) { final JComponent oldEditor = (JComponent)e.getOldValue(); final JComponent newEditor = (JComponent)e.getNewValue(); ui.replaceEditor(oldEditor, newEditor); ui.updateEnabledState(); } else if ("enabled".equals(propertyName)) { ui.updateEnabledState(); } else if (JComponent.TOOL_TIP_TEXT_KEY.equals(propertyName)) { ui.updateToolTipTextForChildren(spinner); } else if ("font".equals(propertyName)) { JComponent editor = spinner.getEditor(); if (editor != null && editor instanceof JSpinner.DefaultEditor) { JTextField tf = ((JSpinner.DefaultEditor) editor).getTextField(); if (tf != null) { if (tf.getFont() instanceof UIResource) { tf.setFont(spinner.getFont()); } } } } } }
void updateToolTipTextForChildren(final JComponent spinnerComponent) { final String toolTipText = spinnerComponent.getToolTipText(); final Component[] children = spinnerComponent.getComponents(); for (final Component element : children) { if (element instanceof JSpinner.DefaultEditor) { final JTextField tf = ((JSpinner.DefaultEditor)element).getTextField(); if (tf != null) { tf.setToolTipText(toolTipText); } } else if (element instanceof JComponent) { ((JComponent)element).setToolTipText(toolTipText); } } }