本文整理汇总了Java中javax.swing.text.NumberFormatter.setAllowsInvalid方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormatter.setAllowsInvalid方法的具体用法?Java NumberFormatter.setAllowsInvalid怎么用?Java NumberFormatter.setAllowsInvalid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter.setAllowsInvalid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeTextFields
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private void initializeTextFields() {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
NumberFormat format = new DecimalFormat("0.00", symbols);
format.setMaximumFractionDigits(2);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setMinimum(0.0);
formatter.setMaximum(10000000.0);
formatter.setAllowsInvalid(false);
this.txtPeso = new JFormattedTextField(formatter);
this.txtPeso.setValue(0.0);
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.gridwidth = 10;
gbc_textField.insets = new Insets(0, 0, 5, 0);
gbc_textField.fill = GridBagConstraints.BOTH;
gbc_textField.gridx = 2;
gbc_textField.gridy = 10;
this.panelSecond.add(this.txtPeso, gbc_textField);
this.txtPeso.setColumns(10);
}
示例2: WettDialog
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Creates a new WettDialog and displays the given array of snails.
* @param parent The Form opening this dialog
* @param schneggen The array of snails to display
* @param wettbueroFactor The factor the Wettbuero uses.
*/
public WettDialog(Frame parent, ArrayList<Rennschnecke> schneggen, double wettbueroFactor) {
super(parent, true);
initComponents();
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
NumberFormatter nf = new NumberFormatter(format);
nf.setMinimum(0.02);
// The maximum bet value is, well, pretty high.
nf.setMaximum(Double.MAX_VALUE / wettbueroFactor);
nf.setAllowsInvalid(false);
nf.setCommitsOnValidEdit(true);
nf.setOverwriteMode(false);
einsatzInput.setFormatterFactory(
new DefaultFormatterFactory(nf)
);
result = null;
snailList.setModel(new DefaultListModel<>());
snailList.setListData(schneggen.toArray(new Rennschnecke[schneggen.size()]));
}
示例3: 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());
}
示例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: 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;
}
示例6: 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());
}
示例7: 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;
}
示例8: getPortValueFormatter
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private NumberFormatter getPortValueFormatter() {
NumberFormat plainIntegerFormat = NumberFormat.getInstance();
plainIntegerFormat.setGroupingUsed(false); // no commas
NumberFormatter portFormatter = new NumberFormatter(plainIntegerFormat);
portFormatter.setValueClass(Integer.class);
portFormatter.setAllowsInvalid(false);
portFormatter.setMinimum(0);
portFormatter.setMaximum(65535);
return portFormatter;
}
示例9: createImageExportWidthPanel
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private void createImageExportWidthPanel() {
imageExportWidth = new JFormattedTextField();
NumberFormat longFormat = NumberFormat.getIntegerInstance();
longFormat.setGroupingUsed(false);
NumberFormatter numberFormatter = new NumberFormatter(longFormat);
numberFormatter.setAllowsInvalid(false);
numberFormatter.setMinimum(0);
numberFormatter.setMaximum(9999);
imageExportWidth = new JFormattedTextField(numberFormatter);
dialog.add(new JLabel("Image initial width [px]"));
dialog.add(imageExportWidth, "wrap");
}
示例10: IntInput
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public IntInput(Question question, Value<?> value) {
mf = new NumberFormatter(NumberFormat.getIntegerInstance());
mf.setAllowsInvalid(false);
widget = new JFormattedTextField(mf);
widget.setColumns(10);
widget.setName(question.getIdent().getName());
setValue(value);
}
示例11: configureFormatter
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private AbstractFormatter configureFormatter() {
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);
return formatter;
}
示例12: initializeTextFields
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private void initializeTextFields() throws ParseException {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
NumberFormat format = new DecimalFormat("0.00", symbols);
format.setMaximumFractionDigits(2);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setMinimum(0.0);
formatter.setMaximum(10000000.0);
formatter.setAllowsInvalid(false);
this.txtCapacidade = new JFormattedTextField(formatter);
this.txtCapacidade.setValue(0.0);
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.insets = new Insets(0, 0, 5, 5);
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
gbc_textField.gridx = 3;
gbc_textField.gridy = 13;
this.panel.add(this.txtCapacidade, gbc_textField);
this.txtCapacidade.setColumns(10);
this.txtCusto = new JFormattedTextField(formatter);
this.txtCusto.setValue(0.0);
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
gbc_textField_1.insets = new Insets(0, 0, 5, 5);
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_textField_1.gridx = 3;
gbc_textField_1.gridy = 18;
this.panel.add(this.txtCusto, gbc_textField_1);
this.txtCusto.setColumns(10);
this.txtTempo = new JFormattedTextField();
this.txtTempo.addKeyListener(new KeyAdapter(){
@Override
public void keyTyped(KeyEvent e){
String numbers = "0123456789";
if(!numbers.contains(e.getKeyChar() + ""))
e.consume();
}
});
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
gbc_textField_2.insets = new Insets(0, 0, 5, 5);
gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
gbc_textField_2.gridx = 3;
gbc_textField_2.gridy = 23;
this.panel.add(this.txtTempo, gbc_textField_2);
this.txtTempo.setColumns(10);
}