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


Java DefaultFormatter.setCommitsOnValidEdit方法代碼示例

本文整理匯總了Java中javax.swing.text.DefaultFormatter.setCommitsOnValidEdit方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFormatter.setCommitsOnValidEdit方法的具體用法?Java DefaultFormatter.setCommitsOnValidEdit怎麽用?Java DefaultFormatter.setCommitsOnValidEdit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.DefaultFormatter的用法示例。


在下文中一共展示了DefaultFormatter.setCommitsOnValidEdit方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setCommitOnValidEdit

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
@Override
public void setCommitOnValidEdit(final boolean commit)
{
	if (textComponent instanceof JFormattedTextField)
	{
		final JFormattedTextField formattedTextField = (JFormattedTextField)textComponent;
		final AbstractFormatter formatter = formattedTextField.getFormatter();
		if (formatter instanceof DefaultFormatter)
		{
			final DefaultFormatter defaultFormatter = (DefaultFormatter)formatter;
			defaultFormatter.setCommitsOnValidEdit(commit);
			return;
		}
	}
	else if (textComponent instanceof JTextArea)
	{
		// ignore it for now
	}
	else
	{
		throw new UnsupportedOperationException("setCommitOnValidValue not supported for " + this);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:24,代碼來源:SwingTerminalTextField.java

示例2: NumberEditor

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
public NumberEditor(String fieldName, Object obj, Field field, int index, Class<?> type, SWFType swfType) {
    setSize(100, getSize().height);
    setMaximumSize(getSize());
    this.obj = obj;
    this.field = field;
    this.index = index;
    this.type = type;
    this.swfType = swfType;
    this.fieldName = fieldName;

    reset();
    JFormattedTextField jtf = ((JSpinner.NumberEditor) getEditor()).getTextField();
    DefaultFormatter formatter = (DefaultFormatter) jtf.getFormatter();
    formatter.setCommitsOnValidEdit(true);

}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:17,代碼來源:NumberEditor.java

示例3: setSpinner

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
private void setSpinner() {
	spinnerAmount.setModel(new SpinnerNumberModel(new Float(0), new Float(0), new Float(Float.MAX_VALUE), new Float(1f)));
	spinnerAmount.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	JTextField tf = ((JSpinner.DefaultEditor) spinnerAmount.getEditor()).getTextField();
	tf.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	tf.setHorizontalAlignment(SwingConstants.CENTER);
	JFormattedTextField field = (JFormattedTextField) spinnerAmount.getEditor().getComponent(0);
	DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
	JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinnerAmount.getEditor();  
       DecimalFormat format = editor.getFormat();  
       format.setMinimumFractionDigits(8);  
       
	//tf.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	//tf.setHorizontalAlignment(SwingConstants.CENTER);
       //DecimalFormat format = editor.getFormat();  
       //format.setMinimumFractionDigits(8);  
}
 
開發者ID:pavel4n,項目名稱:wowdoge.org,代碼行數:19,代碼來源:DialogRequestPayment.java

示例4: NumberField

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
/** Creates a new instance of NumberField */
public NumberField() {
    
    // define a custom input verifier
    this.setInputVerifier(new NumberVerifier());
    
    // create a formatter for displaying and editing
    DefaultFormatter formatter = new DefaultFormatter();
    
    // allow the user to completely delete all text
    formatter.setAllowsInvalid(true);
    
    // typing should insert new characters and not overwrite old ones
    formatter.setOverwriteMode(false);
    
    // commit on edit, otherwise a property change event is generated
    // when the field loses the focus and the value changed since it gained
    // the focus.
    formatter.setCommitsOnValidEdit(true);
    
    // getValue should return a Double object
    formatter.setValueClass(java.lang.Double.class);
    
    // the kind of formatter getFormatter should return
    this.setFormatterFactory(new DefaultFormatterFactory(formatter));
    
    // default value is 0
    this.setValue(new Double(0));
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:30,代碼來源:NumberField.java

示例5: IntegerSpinner

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
/**
 * Instantiates a new value spinner.
 */
public IntegerSpinner(int min, int max, int stepSize) {
    SpinnerNumberModel model = new SpinnerNumberModel(min, min, max, stepSize);
    setModel(model);

    JComponent comp = getEditor();
    final JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
    DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
    addChangeListener(new ChangeListener() {
        private double oldValue = Double.MAX_VALUE;

        @Override
        public void stateChanged(ChangeEvent e) {

            Double doubleValue = IntegerSpinner.this.getDoubleValue();

            if (doubleValue != oldValue) {
                double oldValueCopy = oldValue;

                oldValue = doubleValue;
                if (minIsZero) {
                    if (doubleValue < 0.0) {
                        doubleValue = 0.0;
                        field.setValue(doubleValue);
                    }
                }

                notifyListeners(oldValueCopy, doubleValue);
            }
        }
    });
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:36,代碼來源:IntegerSpinner.java

示例6: createUI

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
/**
 * Creates the ui.
 *
 * @param initialValue the initial value
 * @param min the min
 * @param max the max
 * @param stepSize the step size
 * @param noOfDecimalPlaces the no of decimal places
 */
private void createUI(Double initialValue, Double min, Double max, Double stepSize,
        double noOfDecimalPlaces) {
    SpinnerNumberModel model = new SpinnerNumberModel(initialValue, min, max, stepSize);
    setModel(model);

    JSpinner.NumberEditor editor = (JSpinner.NumberEditor) getEditor();
    DecimalFormat format = editor.getFormat();
    format.setMinimumFractionDigits(3);

    final JFormattedTextField field = (JFormattedTextField) editor.getTextField();
    DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
    addChangeListener(new ChangeListener() {
        private double oldValue = Double.MAX_VALUE;

        @Override
        public void stateChanged(ChangeEvent e) {

            Double doubleValue = DecimalSpinner.this.getDoubleValue();

            if (doubleValue != oldValue) {
                double oldValueCopy = oldValue;

                oldValue = doubleValue;
                if (minIsZero) {
                    if (doubleValue < 0.0) {
                        doubleValue = 0.0;
                        field.setValue(doubleValue);
                    }
                }

                notifyListeners(oldValueCopy, doubleValue);
            }
        }
    });
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:46,代碼來源:DecimalSpinner.java

示例7: initDialog

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
private void initDialog() {
	dialog = new JDialog(mainWindow.getFrame(), true);
	dialog.setLocationRelativeTo(mainWindow.getFrame());
	dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

	Container panel = dialog.getContentPane();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

	JPanel infoPanel = new JPanel();
	infoPanel.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
			FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
			new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
					FormSpecs.DEFAULT_ROWSPEC, }));

	JLabel frequenciaLabel = new JLabel("Frequência:");
	infoPanel.add(frequenciaLabel, "2, 2, left, center");

	frequenciaComboBox = new JComboBox<Frequencia>();
	frequenciaComboBox.setModel(new DefaultComboBoxModel<>(TopMusicalConfiguration.FREQUENCIAS_PERMITIDAS));
	infoPanel.add(frequenciaComboBox, "4, 2, fill, default");

	JLabel quantidadePosicoesLabel = new JLabel("Quantidade de Posições:");
	infoPanel.add(quantidadePosicoesLabel, "2, 4, left, center");

	quantidadePosicoesSpinner = new JSpinner();
	JComponent comp = quantidadePosicoesSpinner.getEditor();
	JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
	DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
	formatter.setCommitsOnValidEdit(true);
	infoPanel.add(quantidadePosicoesSpinner, "4, 4");

	JPanel botoesPanel = new JPanel();

	salvarButton = ButtonFactory.createJButton("Salvar", "Salva as configurações.");
	botoesPanel.add(salvarButton);

	cancelarButton = ButtonFactory.createJButton("Cancelar", "Cancela as alterações feitas");
	botoesPanel.add(cancelarButton);

	panel.add(infoPanel);
	panel.add(botoesPanel);

	dialog.pack();
}
 
開發者ID:Ryudo302,項目名稱:mychart,代碼行數:45,代碼來源:TopMusicalConfigDialog.java

示例8: configure

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
	textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
	formatter.setOverwriteMode(false);
	formatter.setAllowsInvalid(true);
	formatter.setCommitsOnValidEdit(true);
}
 
開發者ID:shevek,項目名稱:spring-rich-client,代碼行數:7,代碼來源:ValueCommitPolicy.java

示例9: spinnerSetCommitOnEdit

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
private static void spinnerSetCommitOnEdit(JSpinner spinner) {
    JComponent comp = spinner.getEditor();
    JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
    DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
}
 
開發者ID:heig-iict-ida,項目名稱:shimmer_move_analyzer,代碼行數:7,代碼來源:CaptureEditFrame.java

示例10: initGUI

import javax.swing.text.DefaultFormatter; //導入方法依賴的package包/類
/**
 * Initializes the graphical user interface for this search implementation.
 * Consists of a textfield for the search term and a checkbox, that is used
 * to hide all nodes that don't match a search string.
 */
private void initGUI() {
	mSearchInputPanel = new JPanel();
	mSearchInputPanel.setLayout(new BoxLayout(mSearchInputPanel,
			BoxLayout.X_AXIS));

	DefaultFormatter formatter = new DefaultFormatter();
	formatter.setOverwriteMode(false);
	formatter.setCommitsOnValidEdit(true);
	mInputTextfield = new JFormattedTextField(formatter);
	mInputTextfield.setToolTipText("<html>Search terms separator: <b>"
			+ SEARCH_TERM_DELIMITER + "</b><br>"
			+ "Inner search term separator: <b>"
			+ SUB_SEARCH_TERM_DELIMITER + "</b><br>"
			+ "Exact match enclosing character: <b>" + ENCLOSING_CHAR
			+ "</b><br>"
			+ "Example: ip,10.0.0;mac,\"aa:bb:cc:dd:ee:ff\"<br>" 
			+ " detects and highlights all nodes that <b>contain</b> the strings "
			+ "<i>ip</i> and <i>10.0.0</i>,<br>"
			+ "as well as all nodes that <b>contain</b> the string mac and <b>exactly contain</b> "
			+ "the value <i>aa:bb:cc:dd:ee:ff</i>" + "</html>");

	mInputTextfield.addPropertyChangeListener(new PropertyChangeListener() {
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			mSearchableGraphPanel.search(mInputTextfield.getText());
		}
	});

	mHideSearchMismatchCheckbox = new JCheckBox();
	mHideSearchMismatchCheckbox.addItemListener(new ItemListener() {
		@Override
		public void itemStateChanged(ItemEvent e) {
			mSearchableGraphPanel
					.setHideSearchMismatches(mHideSearchMismatchCheckbox
							.isSelected());
		}
	});

	mSearchInputPanel.add(new JLabel("Search: "));
	mSearchInputPanel.add(mInputTextfield);
	mSearchInputPanel.add(new JLabel("Hide search mismatches: "));
	mSearchInputPanel.add(mHideSearchMismatchCheckbox);
}
 
開發者ID:trustathsh,項目名稱:visitmeta,代碼行數:49,代碼來源:SimpleSearchAndNoFilter.java


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