本文整理汇总了Java中javax.swing.text.NumberFormatter.setFormat方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormatter.setFormat方法的具体用法?Java NumberFormatter.setFormat怎么用?Java NumberFormatter.setFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter.setFormat方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IntegerEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
ftf.getActionMap().put("check", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { // The text is invalid.
if (userSaysRevert()) { // reverted
ftf.postActionEvent(); // inform the editor
}
} else
try { // The text is valid,
ftf.commitEdit(); // so use it.
ftf.postActionEvent(); // stop editing
} catch (java.text.ParseException exc) {
}
}
});
}
示例2: IntegerEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField)getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
//Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(
new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
//React when the user presses Enter while the editor is
//active. (Tab is handled as specified by
//JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, 0),
"check");
ftf.getActionMap().put("check", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { //The text is invalid.
if (userSaysRevert()) { //reverted
ftf.postActionEvent(); //inform the editor
}
} else try { //The text is valid,
ftf.commitEdit(); //so use it.
ftf.postActionEvent(); //stop editing
} catch (java.text.ParseException exc) { }
}
});
}
示例3: NumberTableCellEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public NumberTableCellEditor() {
super(new JFormattedTextField());
ftf = (JFormattedTextField)getComponent();
//Set up the editor for the Number cells.
floatFormat = org.fhcrc.cpl.viewer.gui.MRMDialog.peaksData.floatFormat;
NumberFormatter floatFormatter = new NumberFormatter(floatFormat);
floatFormatter.setFormat(floatFormat);
ftf.setFormatterFactory(
new DefaultFormatterFactory(floatFormatter));
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
//React when the user presses Enter while the editor is
//active. (Tab is handled as specified by
//JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, 0),
"check");
ftf.getActionMap().put("check", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { //The text is invalid.
if (userSaysRevert()) { //reverted
ftf.postActionEvent(); //inform the editor
}
} else try { //The text is valid,
ftf.commitEdit(); //so use it.
ftf.postActionEvent(); //stop editing
} catch (java.text.ParseException exc) { }
}
});
}
示例4: IntegerCellEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Constructor.
* @param min the minimum of valid values.
* @param max the maximum of valid values.
*/
public IntegerCellEditor(int min, int max) {
super(new JFormattedTextField());
textField = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setOverwriteMode(false);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
textField.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
textField.setValue(minimum);
textField.setHorizontalAlignment(JTextField.TRAILING);
textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
textField.getActionMap().put("check", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!textField.isEditValid()) { //The text is invalid.
Toolkit.getDefaultToolkit().beep();
textField.selectAll();
} else {
try { //The text is valid,
textField.commitEdit(); //so use it.
textField.postActionEvent(); //stop editing
} catch (java.text.ParseException ex) {
}
}
}
});
}
示例5: DoubleCellEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* Constructor.
* @param min the minimum of valid values.
* @param max the maximum of valid values.
*/
public DoubleCellEditor(double min, double max) {
super(new JFormattedTextField());
textField = (JFormattedTextField) getComponent();
minimum = new Double(min);
maximum = new Double(max);
// Set up the editor for the double cells.
doubleFormat = NumberFormat.getNumberInstance();
NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
doubleFormatter.setFormat(doubleFormat);
doubleFormatter.setOverwriteMode(false);
doubleFormatter.setMinimum(minimum);
doubleFormatter.setMaximum(maximum);
textField.setFormatterFactory(new DefaultFormatterFactory(doubleFormatter));
textField.setValue(minimum);
textField.setHorizontalAlignment(JTextField.TRAILING);
textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
textField.getActionMap().put("check", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!textField.isEditValid()) { //The text is invalid.
Toolkit.getDefaultToolkit().beep();
textField.selectAll();
} else {
try { //The text is valid,
textField.commitEdit(); //so use it.
textField.postActionEvent(); //stop editing
} catch (java.text.ParseException ex) {
}
}
}
});
}
示例6: IntegerEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
* TODO
*
* @param min
* @param max
*/
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
ftf.getActionMap().put("check", new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid())
{ // The text is invalid.
if (userSaysRevert())
{ // reverted
ftf.postActionEvent(); // inform the editor
}
}
else
{
try
{ // The text is valid,
ftf.commitEdit(); // so use it.
ftf.postActionEvent(); // stop editing
}
catch (java.text.ParseException exc)
{
}
}
}
});
}
示例7: IntegerEditor
import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField)getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
//Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(
new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
//React when the user presses Enter while the editor is
//active. (Tab is handled as specified by
//JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, 0),
"check");
ftf.getActionMap().put("check", new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 4763225792443612979L;
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { //The text is invalid.
if (userSaysRevert()) { //reverted
ftf.postActionEvent(); //inform the editor
}
} else try { //The text is valid,
ftf.commitEdit(); //so use it.
ftf.postActionEvent(); //stop editing
} catch (java.text.ParseException exc) { }
}
});
}