当前位置: 首页>>代码示例>>Java>>正文


Java JFormattedTextField.setFocusLostBehavior方法代码示例

本文整理汇总了Java中javax.swing.JFormattedTextField.setFocusLostBehavior方法的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField.setFocusLostBehavior方法的具体用法?Java JFormattedTextField.setFocusLostBehavior怎么用?Java JFormattedTextField.setFocusLostBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JFormattedTextField的用法示例。


在下文中一共展示了JFormattedTextField.setFocusLostBehavior方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: IntegerEditor

import javax.swing.JFormattedTextField; //导入方法依赖的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) {
                }
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:38,代码来源:IntegerEditor.java

示例2: DateCellEditor

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
 * Constructor.
 */
public DateCellEditor(DateFormat dateFormat) {
    super(new JFormattedTextField());
    textField = (JFormattedTextField) getComponent();

    this.dateFormat = dateFormat;
    DateFormatter dateFormatter = new DateFormatter(dateFormat);

    textField.setFormatterFactory(new DefaultFormatterFactory(dateFormatter));
    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) {
                }
            }
        }
    });
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:36,代码来源:DateCellEditor.java

示例3: IntegerCellEditor

import javax.swing.JFormattedTextField; //导入方法依赖的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) {
                }
            }
        }
    });
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:46,代码来源:IntegerCellEditor.java

示例4: DoubleCellEditor

import javax.swing.JFormattedTextField; //导入方法依赖的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) {
                }
            }
        }
    });
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:46,代码来源:DoubleCellEditor.java


注:本文中的javax.swing.JFormattedTextField.setFocusLostBehavior方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。