javax.swing.JFormattedTextField#setFormatterFactory ( )源码实例Demo

下面列出了javax.swing.JFormattedTextField#setFormatterFactory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pcgen   文件: SkillInfoTab.java
private SkillRankSpinnerEditor(SkillRankSpinnerModel model)
{
	super(model);
	this.model = model;

	DefaultEditor editor = new DefaultEditor(spinner);
	NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0.#")); //$NON-NLS-1$
	formatter.setValueClass(Float.class);
	DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);

	JFormattedTextField ftf = editor.getTextField();
	ftf.setEditable(true);
	ftf.setFormatterFactory(factory);
	ftf.setHorizontalAlignment(SwingConstants.RIGHT);

	spinner.setEditor(editor);
}
 
源代码2 项目: atdl4j   文件: SwingNullableSpinner.java
private NumberEditorNull(JSpinner spinner, DecimalFormat format) {
	super(spinner);
	if (!(spinner.getModel() instanceof SpinnerNumberModelNull)) {
		return;
	}
	
	SpinnerNumberModelNull model = (SpinnerNumberModelNull) spinner.getModel();
	NumberFormatter formatter = new NumberEditorFormatterNull(model, format);
	DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
	JFormattedTextField ftf = getTextField();
	ftf.setEditable(true);
	ftf.setFormatterFactory(factory);
	ftf.setHorizontalAlignment(JTextField.RIGHT);
	
	try {
		String maxString = formatter.valueToString(model.getMinimum());
		String minString = formatter.valueToString(model.getMaximum());
		ftf.setColumns(Math.max(maxString.length(), minString.length()));
	}
	catch (ParseException e) {
		// TBD should throw a chained error here
	}
}
 
源代码3 项目: pcgen   文件: SkillInfoTab.java
private SkillRankSpinnerEditor(SkillRankSpinnerModel model)
{
	super(model);
	this.model = model;

	DefaultEditor editor = new DefaultEditor(spinner);
	NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0.#")); //$NON-NLS-1$
	formatter.setValueClass(Float.class);
	DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);

	JFormattedTextField ftf = editor.getTextField();
	ftf.setEditable(true);
	ftf.setFormatterFactory(factory);
	ftf.setHorizontalAlignment(SwingConstants.RIGHT);

	spinner.setEditor(editor);
}
 
源代码4 项目: jdk1.8-source-analysis   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码5 项目: dragonwell8_jdk   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码6 项目: TencentKona-8   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码7 项目: jdk8u60   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码8 项目: openjdk-jdk8u   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码9 项目: marathonv5   文件: IntegerEditor.java
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) {
                }
        }
    });
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码11 项目: Bytecoder   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码12 项目: openjdk-jdk9   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码13 项目: audiveris   文件: LHexaSpinner.java
HexaEditor (JSpinner spinner)
{
    super(spinner);

    JFormattedTextField ftf = getTextField();
    ftf.setEditable(true);
    ftf.setFormatterFactory(new HexaFormatterFactory());
}
 
源代码14 项目: microba   文件: NoGroupingSpinner.java
public NoGroupingNumberEditor(JSpinner spinner, SpinnerModel model) {
	super(spinner);
	JFormattedTextField ftf = (JFormattedTextField) this
			.getComponent(0);
	NumberFormat fmt = NumberFormat.getIntegerInstance();
	fmt.setGroupingUsed(false);
	ftf.setFormatterFactory(new DefaultFormatterFactory(
			new NumberFormatter(fmt)));
	revalidate();
}
 
源代码15 项目: jdk8u-jdk   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码16 项目: openjdk-8   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码17 项目: jdk8u_jdk   文件: ValueFormatter.java
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
 
源代码18 项目: pcgen   文件: IntegerEditor.java
public IntegerEditor(int min, int max)
{
	super(new JFormattedTextField());
	ftf = (JFormattedTextField) getComponent();
	minimum = min;
	maximum = 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(SwingConstants.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()
	{

		@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)
				{
				}
			}
		}

	});
}
 
/**
 * Creates a {@link JFormattedTextField} for the specified cell. If a formatter is given, will
 * apply it to the field. Does not validate the model, so make sure this call works!
 * 
 * @param model
 * @param rowIndex
 * @param columnIndex
 * @param cellClass
 * @param formatter
 *            the formatter or <code>null</code> if none is required
 * @param hideUnavailableContentAssist
 * @return
 */
public CellTypeTextFieldDefaultImpl(final TablePanelModel model, final int rowIndex, final int columnIndex,
		final Class<? extends CellType> cellClass, AbstractFormatter formatter, boolean hideUnavailableContentAssist) {
	super();

	final JFormattedTextField field = CellTypeImplHelper.createFormattedTextField(model, rowIndex, columnIndex);
	setLayout(new BorderLayout());
	add(field, BorderLayout.CENTER);

	// otherwise 'null' would be restored
	Object value = model.getValueAt(rowIndex, columnIndex);
	String text = value != null ? String.valueOf(value) : "";

	// specical handling when formatter is given
	if (formatter != null) {
		field.setFormatterFactory(new DefaultFormatterFactory(formatter));
	}
	field.setText(text);

	// set syntax assist if available
	String syntaxHelp = model.getSyntaxHelpAt(rowIndex, columnIndex);
	if (syntaxHelp != null && !"".equals(syntaxHelp.trim())) {
		SwingTools.setPrompt(syntaxHelp, field);
	}

	// see if content assist is possible for this field, if so add it
	ImageIcon icon = SwingTools.createIcon("16/"
			+ I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist.icon"));
	JButton contentAssistButton = new JButton();
	contentAssistButton.setIcon(icon);
	if (field.isEnabled() && model.isContentAssistPossibleForCell(rowIndex, columnIndex)) {
		contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
				"gui.action.content_assist_enabled.tip"));
		CellTypeImplHelper.addContentAssist(model, rowIndex, columnIndex, field, contentAssistButton, cellClass);
	} else {
		contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
				"gui.action.content_assist_disabled.tip"));
		contentAssistButton.setEnabled(false);
	}
	if (contentAssistButton.isEnabled() || (!contentAssistButton.isEnabled() && !hideUnavailableContentAssist)) {
		add(contentAssistButton, BorderLayout.EAST);
	}

	// set size so panels don't grow larger when they get the chance
	setPreferredSize(new Dimension(300, 20));
	setMinimumSize(new Dimension(100, 15));
	setMaximumSize(new Dimension(1600, 30));
}
 
源代码20 项目: pcgen   文件: IntegerEditor.java
public IntegerEditor(int min, int max)
{
	super(new JFormattedTextField());
	ftf = (JFormattedTextField) getComponent();
	minimum = min;
	maximum = 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(SwingConstants.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()
	{

		@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)
				{
				}
			}
		}

	});
}