當前位置: 首頁>>代碼示例>>Java>>正文


Java NumberFormatter.setValueClass方法代碼示例

本文整理匯總了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());
}
 
開發者ID:girtel,項目名稱:Net2Plan,代碼行數:21,代碼來源:JNumberField.java

示例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;
}
 
開發者ID:sing-group,項目名稱:la-images,代碼行數:26,代碼來源:ExportAllAsPngDialog.java

示例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;
}
 
開發者ID:sing-group,項目名稱:la-images,代碼行數:26,代碼來源:ExportAsPngDialog.java

示例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;
}
 
開發者ID:Exslims,項目名稱:MercuryTrade,代碼行數:23,代碼來源:ComponentsFactory.java

示例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);
}
 
開發者ID:vrsl,項目名稱:MDD-JPA,代碼行數:24,代碼來源:JIntegerTextField.java

示例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;
}
 
開發者ID:defano,項目名稱:hypertalk-java,代碼行數:26,代碼來源:StackSizeEditor.java

示例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;
}
 
開發者ID:jpschewe,項目名稱:fll-sw,代碼行數:22,代碼來源:FormatterUtils.java

示例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());

}
 
開發者ID:machaval,項目名稱:mule-intellij-plugins,代碼行數:15,代碼來源:MuleRemoteDebuggerConfPanel.java

示例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;
}
 
開發者ID:kartoFlane,項目名稱:hiervis,代碼行數:16,代碼來源:HKOptionsPanel.java

示例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;
}
 
開發者ID:pushkarkp,項目名稱:twidlit,代碼行數:8,代碼來源:IntegerTextField.java

示例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));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:16,代碼來源:NumberEditorExtTest.java

示例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));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:17,代碼來源:NumberEditorExtTest.java

示例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));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:17,代碼來源:NumberEditorExtTest.java

示例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);
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:8,代碼來源:NumberEditorExtTest.java


注:本文中的javax.swing.text.NumberFormatter.setValueClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。