本文整理汇总了Java中javax.swing.JSpinner.DefaultEditor类的典型用法代码示例。如果您正苦于以下问题:Java DefaultEditor类的具体用法?Java DefaultEditor怎么用?Java DefaultEditor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultEditor类属于javax.swing.JSpinner包,在下文中一共展示了DefaultEditor类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyPressed
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
@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);
}
示例2: reset
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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);
}
示例3: reset
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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);
}
示例4: buildPanel
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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);
}
}
示例5: fixupEditor
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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));
}
}
示例6: fixupEditor
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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));
}
}
示例7: testDefaultFont
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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");
}
}
示例8: createEditor
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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;
}
示例9: getEditor
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
/**
* @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();
}
}
示例10: getTextComponent
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
/**
* 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;
}
示例11: run
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
@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);
}
示例12: SlidingSpinner
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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);
}
示例13: propertyChange
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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());
}
}
}
}
}
}
示例14: updateToolTipTextForChildren
import javax.swing.JSpinner.DefaultEditor; //导入依赖的package包/类
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);
}
}
}