本文整理汇总了Java中javax.swing.text.NumberFormatter.setValueClass方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormatter.setValueClass方法的具体用法?Java NumberFormatter.setValueClass怎么用?Java NumberFormatter.setValueClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter.setValueClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JNumberField
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public JNumberField(double defaultNumber, double minValue, double maxValue, double increment)
{
super(new SpinnerNumberModel(defaultNumber, minValue, maxValue, increment));
final NumberEditor editor = (NumberEditor) this.getEditor();
editor.getFormat().setMinimumFractionDigits(2);
editor.getFormat().setMaximumFractionDigits(6);
final JFormattedTextField spinnerTextEditor = editor.getTextField();
spinnerTextEditor.setColumns(6);
spinnerTextEditor.setHorizontalAlignment(JTextField.CENTER);
final NumberFormatter numberFormatter = new NumberFormatter(editor.getFormat());
numberFormatter.setValueClass(Double.class);
numberFormatter.setMinimum(0d);
numberFormatter.setMaximum(Double.MAX_VALUE);
numberFormatter.setAllowsInvalid(false);
spinnerTextEditor.setFormatterFactory(new JFormattedTextField(numberFormatter).getFormatterFactory());
}
示例2: getImageSizePanel
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private JPanel getImageSizePanel() {
JPanel imageSizePanel = new JPanel();
imageSizePanel.setLayout(new GridLayout(1, 4));
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setCommitsOnValidEdit(true);
widthTF = new JFormattedTextField(formatter);
widthTF.setValue(1200);
addFocusListener(widthTF);
heightTF = new JFormattedTextField(formatter);
heightTF.setValue(1000);
addFocusListener(heightTF);
imageSizePanel.add(new JLabel(" Width:"));
imageSizePanel.add(widthTF);
imageSizePanel.add(new JLabel(" Height:"));
imageSizePanel.add(heightTF);
return imageSizePanel;
}
示例3: getImageSizePanel
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private JPanel getImageSizePanel() {
JPanel imageSizePanel = new JPanel();
imageSizePanel.setLayout(new GridLayout(1, 4));
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setCommitsOnValidEdit(true);
widthTF = new JFormattedTextField(formatter);
widthTF.setValue(1200);
widthTF.addFocusListener(FOCUS_LISTENER);
heightTF = new JFormattedTextField(formatter);
heightTF.setValue(1000);
heightTF.addFocusListener(FOCUS_LISTENER);
imageSizePanel.add(new JLabel(" Width:"));
imageSizePanel.add(widthTF);
imageSizePanel.add(new JLabel(" Height:"));
imageSizePanel.add(heightTF);
return imageSizePanel;
}
示例4: getIntegerTextField
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer value) {
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(min);
formatter.setMaximum(max);
formatter.setAllowsInvalid(true);
formatter.setCommitsOnValidEdit(false);
JFormattedTextField field = new JFormattedTextField(formatter);
field.setValue(value);
field.setFont(REGULAR_FONT.deriveFont(scale * 18));
field.setFocusLostBehavior(JFormattedTextField.PERSIST);
field.setForeground(AppThemeColor.TEXT_DEFAULT);
field.setCaretColor(AppThemeColor.TEXT_DEFAULT);
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(AppThemeColor.BORDER, 1),
BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3)
));
field.setBackground(AppThemeColor.HEADER);
return field;
}
示例5: JIntegerTextField
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public JIntegerTextField() {
super();
DecimalFormat df = new DecimalFormat("####");
nf = new NumberFormatter(df) {
@Override
public String valueToString(Object iv) throws ParseException {
if ((iv == null) || (((Number) iv).intValue() == -1)) {
return "";
}
return super.valueToString(iv);
}
@Override
public Object stringToValue(String text) throws ParseException {
if ("".equals(text)) {
return null;
}
return super.stringToValue(text);
}
};
nf.setValueClass(Integer.class);
this.setFormatter(nf);
}
示例6: editStackSize
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public static Dimension editStackSize(Dimension currentSize, Component parent) {
StackSizeEditor dialog = new StackSizeEditor();
dialog.stackDimension = currentSize;
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
dialog.newHeight.setFormatterFactory(new DefaultFormatterFactory(formatter));
dialog.newWidth.setFormatterFactory(new DefaultFormatterFactory(formatter));
dialog.currentStackSize.setText("Stack is " + currentSize.width + "px by " + currentSize.height + "px");
dialog.newWidth.setText(String.valueOf(currentSize.width));
dialog.newHeight.setText(String.valueOf(currentSize.height));
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
return dialog.stackDimension;
}
示例7: createIntegerField
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* @param min minimum value
* @param max maximum value
* @return text field for editing integers
*/
public static JFormattedTextField createIntegerField(final int min,
final int max) {
final NumberFormatter def = new NumberFormatter();
def.setValueClass(Integer.class);
final NumberFormatter disp = new NumberFormatter((new DecimalFormat("#,###,##0")));
disp.setValueClass(Integer.class);
final NumberFormatter ed = new NumberFormatter((new DecimalFormat("#,###,##0")));
ed.setValueClass(Integer.class);
final DefaultFormatterFactory factory = new DefaultFormatterFactory(def, disp, ed);
final JFormattedTextField field = new JFormattedTextField(factory);
field.setValue(Integer.valueOf(min));
field.setInputVerifier(new IntegerVerifier(min, max));
return field;
}
示例8: createUIComponents
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private void createUIComponents() {
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMaximum(65535);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
portTextField = new JFormattedTextField(formatter);
jvmPortTextField = new JFormattedTextField(formatter);
appsMap = new JBTable(new ModulesTableModel());
}
示例9: buildNumberTextField
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private static JTextField buildNumberTextField()
{
// TODO: Verifying user input
NumberFormatter formatter = new NumberFormatter( new DecimalFormat( "0" ) );
formatter.setValueClass( Integer.class );
formatter.setMinimum( Integer.MIN_VALUE );
formatter.setMaximum( Integer.MAX_VALUE );
formatter.setAllowsInvalid( false );
JFormattedTextField result = new JFormattedTextField();
result.setHorizontalAlignment( SwingConstants.RIGHT );
result.setColumns( 10 );
return result;
}
示例10: createFormatter
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private static NumberFormatter createFormatter(int min, int max) {
NumberFormatter nf = new NumberFormatter(NumberFormat.getInstance());
nf.setValueClass(Integer.class);
nf.setMinimum(min);
nf.setMaximum(max);
return nf;
}
示例11: createUIComponents
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Custom initialization code from form
*/
private void createUIComponents() {
NumberFormat numberFormat = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(numberFormat);
formatter.setValueClass(Integer.class);
formatter.setMaximum(1000);
formatter.setMinimum(1);
formatter.setCommitsOnValidEdit(true);
formatter.setOverwriteMode(true);
pasteToFetch = new JFormattedTextField(formatter);
pasteToFetch.setValue(50);
}
开发者ID:kennedyoliveira,项目名称:ultimate-pastebin-intellij-plugin,代码行数:17,代码来源:PasteBinConfigurationForm.java
示例12: testFloatStringToValuePositive
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Issue #1528-swingx: numbereditor doesn't allow negative values.
*
* Sanity: positive okay
* @throws ParseException
*/
@Test
public void testFloatStringToValuePositive() throws ParseException {
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new StrictNumberFormatter(format);
formatter.setValueClass(Float.class);
float value = 3.4f;
String text = format.format(value);
assertEquals("string: " + text, value, formatter.stringToValue(text));
}
示例13: testFloatStringToValueZero
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Issue #1528-swingx: numbereditor doesn't allow negative values.
*
* Test zero
*
* @throws ParseException
*/
@Test
public void testFloatStringToValueZero() throws ParseException {
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new StrictNumberFormatter(format);
formatter.setValueClass(Float.class);
float value = 0f;
String text = format.format(value);
assertEquals("string: " + text, value, formatter.stringToValue(text));
}
示例14: testFloatStringToValueNegative
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Issue #1528-swingx: numbereditor doesn't allow negative values.
*
* Test negative
*
* @throws ParseException
*/
@Test
public void testFloatStringToValueNegative() throws ParseException {
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new StrictNumberFormatter(format);
formatter.setValueClass(Float.class);
float value = -3.4f;
String text = format.format(value);
assertEquals("string: " + text, value, formatter.stringToValue(text));
}
示例15: testStrictNumberFormatterAutoRangeInteger
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
@Test (expected = ParseException.class)
public void testStrictNumberFormatterAutoRangeInteger() throws ParseException {
NumberFormat format = NumberFormat.getIntegerInstance();
NumberFormatter formatter = new StrictNumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.stringToValue(TOO_BIG_INTEGER);
}