本文整理汇总了Java中javax.swing.JFormattedTextField类的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField类的具体用法?Java JFormattedTextField怎么用?Java JFormattedTextField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JFormattedTextField类属于javax.swing包,在下文中一共展示了JFormattedTextField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Limpar_Campos_Tela
import javax.swing.JFormattedTextField; //导入依赖的package包/类
public static void Limpar_Campos_Tela(JPanel tela) {
for (Component componente : tela.getComponents()) {
if (componente instanceof JPanel) {
Limpar_Campos_Tela((JPanel) componente);
}
if (componente instanceof JTextField) {
((JTextField) componente).setText("");
}
if (componente instanceof JFormattedTextField) {
((JFormattedTextField) componente).setText("");
}
if(componente instanceof JScrollPane){
JViewport viewport = ((JScrollPane)componente).getViewport();
JTable table = (JTable)viewport.getView();
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.getDataVector().removeAllElements();
model.fireTableDataChanged();
}
}
}
示例2: initializeTextFields
import javax.swing.JFormattedTextField; //导入依赖的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);
}
示例3: select
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Selects the passed in field, returning true if it is found, false
* otherwise.
*/
private boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
{
int max = ftf.getDocument().getLength();
iterator.first();
do
{
Map<Attribute, Object> attrs = iterator.getAttributes();
if( attrs != null && attrs.containsKey(field) )
{
int start = iterator.getRunStart(field);
int end = iterator.getRunLimit(field);
if( start != -1 && end != -1 && start <= max && end <= max )
{
ftf.select(start, end);
}
return true;
}
}
while( iterator.next() != CharacterIterator.DONE );
return false;
}
示例4: getCellEditorValue
import javax.swing.JFormattedTextField; //导入依赖的package包/类
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Integer) {
return o;
} else if (o instanceof Number) {
return new Integer(((Number) o).intValue());
} else {
if (DEBUG) {
System.out.println("getCellEditorValue: o isn't a Number");
}
try {
return integerFormat.parseObject(o.toString());
} catch (ParseException exc) {
System.err.println("getCellEditorValue: can't parse o: " + o);
return null;
}
}
}
示例5: destacarCampo
import javax.swing.JFormattedTextField; //导入依赖的package包/类
private void destacarCampo(JFormattedTextField field) {
final int timerDelay = 500;
final int totalTime = 2000;
final int totalCount = totalTime / timerDelay;
Timer timer = new Timer(timerDelay, new ActionListener(){
int count = 0;
public void actionPerformed(ActionEvent evt) {
if (count % 2 == 0) {
field.setBorder(new LineBorder(Color.RED, 2, true));
field.requestFocus();
} else {
field.setBorder(new LineBorder(Color.GRAY, 1, false));
if (count >= totalCount) {
((Timer)evt.getSource()).stop();
}
}
count++;
}
});
timer.start();
}
示例6: stopCellEditing
import javax.swing.JFormattedTextField; //导入依赖的package包/类
@Override
public boolean stopCellEditing() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
if (ftf.isEditValid()) {
try {
ftf.commitEdit();
} catch (java.text.ParseException ex) {
}
} else { //text is invalid
Toolkit.getDefaultToolkit().beep();
textField.selectAll();
return false; //don't let the editor go away
}
return super.stopCellEditing();
}
示例7: getCellEditorValue
import javax.swing.JFormattedTextField; //导入依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Integer) {
return o;
} else if (o instanceof Number) {
return new Integer(((Number) o).intValue());
} else {
try {
return integerFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
示例8: getCellEditorValue
import javax.swing.JFormattedTextField; //导入依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Double) {
return o;
} else if (o instanceof Number) {
return new Double(((Number) o).doubleValue());
} else {
try {
return doubleFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
示例9: createMtPanel
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Creates the {@link JPanel} showing the mission time.
*
* @param maxwidth
* the dimension of the longest label
* @return the JPanel showing the mission time
*/
private JPanel createMtPanel(Dimension maxwidth) {
Double mtVal = inverse.evaluate(reliabilityFunction, standardMT);
JLabel pmtLabel = new JLabel("P[MT] =");
pmtLabel.setMinimumSize(maxwidth);
JLabel mtLabel = new JLabel("MT:");
mtLabel.setMinimumSize(maxwidth);
mtProbability = new JFormattedTextField(mtFieldFormat);
mtProbability.addActionListener(MeasurePanel.this);
mtProbability.setPreferredSize(new Dimension(70, 15));
mtProbability.setHorizontalAlignment(SwingConstants.RIGHT);
mtProbability.setText(standardMT.toString());
mt = new JLabel(mtVal.toString());
return createSubPanel("Mission-Time", pmtLabel, mtProbability, mtLabel, mt);
}
示例10: getCalendarField
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Returns the calendarField under the start of the selection, or -1 if
* there is no valid calendar field under the selection (or the spinner
* isn't editing dates.
*/
private int getCalendarField(JSpinner spinner)
{
JComponent editor = spinner.getEditor();
if( editor instanceof JSpinner.DateEditor )
{
JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
JFormattedTextField ftf = dateEditor.getTextField();
int start = ftf.getSelectionStart();
JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
if( formatter instanceof InternationalFormatter )
{
Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
for( int counter = 0; counter < fields.length; counter++ )
{
if( fields[counter] instanceof DateFormat.Field )
{
int calendarField;
if( fields[counter] == DateFormat.Field.HOUR1 )
{
calendarField = Calendar.HOUR;
}
else
{
calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
}
if( calendarField != -1 )
{
return calendarField;
}
}
}
}
}
return -1;
}
示例11: getFormatter
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Returns either the default formatter, display formatter, editor
* formatter or null formatter based on the state of the
* JFormattedTextField.
*
* @param source JFormattedTextField requesting
* JFormattedTextField.AbstractFormatter
* @return JFormattedTextField.AbstractFormatter to handle
* formatting duties.
*/
public JFormattedTextField.AbstractFormatter getFormatter(
JFormattedTextField source) {
JFormattedTextField.AbstractFormatter format = null;
if (source == null) {
return null;
}
Object value = source.getValue();
if (value == null) {
format = getNullFormatter();
}
if (format == null) {
if (source.hasFocus()) {
format = getEditFormatter();
}
else {
format = getDisplayFormatter();
}
if (format == null) {
format = getDefaultFormatter();
}
}
return format;
}
示例12: SingleIntegerFieldOptionsPanel
import javax.swing.JFormattedTextField; //导入依赖的package包/类
public SingleIntegerFieldOptionsPanel(String labelString,
final InspectionProfileEntry owner,
@NonNls final String property,
int integerFieldColumns) {
super(new GridBagLayout());
final JLabel label = new JLabel(labelString);
final JFormattedTextField valueField = createIntegerFieldTrackingValue(owner, property, integerFieldColumns);
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets.right = UIUtil.DEFAULT_HGAP;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.BASELINE_LEADING;
constraints.fill = GridBagConstraints.NONE;
add(label, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.insets.right = 0;
constraints.anchor = GridBagConstraints.BASELINE_LEADING;
constraints.fill = GridBagConstraints.NONE;
add(valueField, constraints);
}
示例13: stringToValue
import javax.swing.JFormattedTextField; //导入依赖的package包/类
@Override
public Object stringToValue (String string)
throws ParseException
{
try {
JFormattedTextField ftf = getFormattedTextField();
Object value = ftf.getValue();
if (value instanceof Integer) {
return Integer.valueOf(string, 16);
} else if (value instanceof Long) {
return Long.valueOf(string, 16);
} else {
throw new IllegalArgumentException(
"Illegal Number class for HexaFormatter " + value.getClass());
}
} catch (NumberFormatException ex) {
throw new ParseException(string, 0);
}
}
示例14: fixIntegerList
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Workaround for a swing bug : when the user enters an illegal value, the
* text is forced to the last value.
*
* @param spinner the spinner to update
*/
public static void fixIntegerList (final JSpinner spinner)
{
JSpinner.DefaultEditor editor;
editor = (JSpinner.DefaultEditor) spinner.getEditor();
final JFormattedTextField ftf = editor.getTextField();
ftf.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterAction");
ftf.getActionMap().put(
"enterAction",
new AbstractAction()
{
@Override
public void actionPerformed (ActionEvent e)
{
try {
spinner.setValue(Integer.parseInt(ftf.getText()));
} catch (Exception ex) {
// Reset to last value
ftf.setText(ftf.getValue().toString());
}
}
});
}
示例15: setupIntegerFieldTrackingValue
import javax.swing.JFormattedTextField; //导入依赖的package包/类
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
final InspectionProfileEntry owner,
final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property,
((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}