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


Java MaskFormatter类代码示例

本文整理汇总了Java中javax.swing.text.MaskFormatter的典型用法代码示例。如果您正苦于以下问题:Java MaskFormatter类的具体用法?Java MaskFormatter怎么用?Java MaskFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getFormat

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * Returns format's pattern. 
 * 
 * @return format's pattern.
 */
public String getFormat() {
    if (format != null) return format;
    String fmt = null;
    if (formatter instanceof MaskFormatter) {
        fmt = ((MaskFormatter)formatter).getMask();
    } else if (formatter instanceof InternationalFormatter) {
        Format f = ((InternationalFormatter)formatter).getFormat();
        if (f instanceof DecimalFormat) {
            fmt = ((DecimalFormat)f).toPattern();
        } else if (f instanceof SimpleDateFormat) {
            fmt = ((SimpleDateFormat)f).toPattern();
        }
    }
    return fmt;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:FormatSelector.java

示例2: DesktopTimeField

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public DesktopTimeField() {
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);

    digitWidth = getDigitWidth();

    timeFormat = Datatypes.getFormatStringsNN(uss.getLocale()).getTimeFormat();
    resolution = DateField.Resolution.MIN;
    formatter = new MaskFormatter();
    formatter.setPlaceholderCharacter('_');
    impl = new FlushableFormattedTextField(formatter);
    FieldListener listener = new FieldListener();
    impl.addFocusListener(listener);
    impl.addKeyListener(listener);

    setShowSeconds(timeFormat.contains("ss"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:DesktopTimeField.java

示例3: parseString

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public static Object parseString(String value, Object[] pattern) {
	MaskFormatter format = new MaskFormatter();
	format.setValueContainsLiteralCharacters(false);
	Object d = null;

	for (int i = 0; i < pattern.length; i++) {
		try {
			format.setMask(pattern[i].toString());
			d = format.stringToValue(value);
			if (d != null)
				break;
		} catch (Exception e) {
			continue;
		}
	} // End of for loop
	return d;
}
 
开发者ID:arrahtech,项目名称:osdq-core,代码行数:18,代码来源:FormatCheck.java

示例4: validateUsPhoneNumber

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * Instead of using the MaskConverter in the Page, we just validate the value here with a custom validator.
 */
public String validateUsPhoneNumber(final String newValue) {
    try {
        final MaskFormatter maskFormatter = new MaskFormatter("(###) ###-####");
        maskFormatter.setValueClass(String.class);
        maskFormatter.setAllowsInvalid(true);
        maskFormatter.setValueContainsLiteralCharacters(true);
        final Object obj = maskFormatter.stringToValue(newValue);
        if (obj != null) {
            return null;
        }
    } catch (final ParseException e) {
        //ignore
    }
    //so we can provide a different message than "is not a valid string"
    return "does not match the mask";
}
 
开发者ID:subes,项目名称:invesdwin-nowicket,代码行数:20,代码来源:FormInput.java

示例5: AddIPDialog

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public AddIPDialog(JDependCooper frame) throws ParseException {
	super();
	this.frame = frame;

	setSize(250, 100);
	this.setLocationRelativeTo(null);// 窗口在屏幕中间显示

	this.setLayout(new BorderLayout());

	MaskFormatter ipmask = new MaskFormatter("###.###.###.###");
	ipmask.setPlaceholderCharacter(' ');
	field = new JFormattedTextField(ipmask);
	field.setFont(new Font("Courier", Font.PLAIN, 18));
	field.setColumns(16);
	this.add(BorderLayout.CENTER, field);

	JPanel buttonPanel = new JPanel();
	buttonPanel.add(this.createOkButton());
	buttonPanel.add(this.createCloseButton());

	this.add(BorderLayout.SOUTH, buttonPanel);

}
 
开发者ID:jdepend,项目名称:cooper,代码行数:24,代码来源:AddIPDialog.java

示例6: createGridFields

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
private void createGridFields() {
   mGrid = new JFormattedTextField[9][];
   for(int i = 0; i < 9; i++) {
      mGrid[i] = new JFormattedTextField[9];
      for(int j = 0; j < 9; j++) {
           try {
              mGrid[i][j] = new JFormattedTextField(new MaskFormatter("#"));
           }
           catch (ParseException ex) {
				System.err.println("ParseException while creating grid.");
              System.exit(1);
           }
           mGrid[i][j].setHorizontalAlignment(JFormattedTextField.CENTER);
           mGrid[i][j].setForeground(Color.BLACK);
		   mGrid[i][j].addKeyListener(getGridKeyAdapter(i, j));
		   mGrid[i][j].addMouseListener(getGridMouseAdapter(mGrid[i][j]));
      }
   }
}
 
开发者ID:kjarosz,项目名称:Sudoku-Solver,代码行数:20,代码来源:SudokuSolver.java

示例7: Formatacoes

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/** Inicializa os campos */
protected Formatacoes()
{
	try {
		cpf = new MaskFormatter("###.###.###-##");
		cpf.setPlaceholderCharacter('_');
		rg = new MaskFormatter("#########");
		rg.setPlaceholderCharacter('_');
		telefone = new MaskFormatter("####-####");
		telefone.setPlaceholderCharacter('_');
		telefone2 = new MaskFormatter("####-####");
		telefone2.setPlaceholderCharacter('_');
		data = new MaskFormatter("##/##/####");
		data.setPlaceholderCharacter('_');
		cep = new MaskFormatter("#####-###");
		cep.setPlaceholderCharacter('_');
		tipo = new MaskFormatter("U");
		tipo.setPlaceholder(" ");
		tipo.setValidCharacters("CFA");
	} catch (ParseException e) {
		JOptionPane.showMessageDialog(null,"ERRO: N�o foi poss�vel criar as m�scaras dos campos da janela.");
	}
}
 
开发者ID:andreimesquita,项目名称:Cine-Movies,代码行数:24,代码来源:Formatacoes.java

示例8: ScheduleDurationField

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * @param value the duration to use for the initial value, may not be null
 */
public ScheduleDurationField(final Duration value) {
  setInputVerifier(new TimeVerifier());

  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setDuration(value);
}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:19,代码来源:ScheduleDurationField.java

示例9: createMaskFormatter

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * Creates a {@link MaskFormatter} from a given pattern.
 *
 * @param format for the formatter
 * @return created {@link MaskFormatter}
 * @throws ParseException
 * @see MaskFormatter
 * @since 0.0.1
 */
public static MaskFormatter createMaskFormatter(final String format) throws ParseException {
	if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(format));
	if (null == format) {
		throw new RuntimeExceptionIsNull("format"); //$NON-NLS-1$
	}

	final MaskFormatter result = new MaskFormatter(format) {
		private static final long serialVersionUID = 5212947957420446007L;

		{
			setCommitsOnValidEdit(true);
			setPlaceholderCharacter('_');
		}
	};

	if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
	return result;
}
 
开发者ID:slaubenberger,项目名称:wichtel,代码行数:28,代码来源:FormatFactory.java

示例10: init

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
private void init() {
	//create the CellContraints
	cc  = new CellConstraints();
	
	// create the Layout for Panel this
	String panelColumns = "pref,3dlu,fill:pref:grow";
	String panelRows = "pref";
	FormLayout panelLayout = new FormLayout(panelColumns, panelRows);
	this.setLayout(panelLayout);
	
	this.marker = new JLabel(label+":");
	this.valueField = new JFormattedTextField();
	if (this.valueField.getBackground().equals(Color.BLACK)) {
		this.valueField.setBackground(Color.WHITE);
	}
	
	try {
	        mf = new MaskFormatter ("##");
	} catch (java.text.ParseException e) {
		
	}
	javax.swing.text.DefaultFormatterFactory dff = new  DefaultFormatterFactory(mf);
	valueField.setFormatterFactory(dff);
	valueField.addFocusListener(listener);
	
	this.add(marker, cc.xy(1, 1));
	this.add(valueField, cc.xy(3,1));
}
 
开发者ID:lazyzero,项目名称:kkMulticopterFlashTool,代码行数:29,代码来源:JNamedIntMenuItem.java

示例11: formatarString

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public static String formatarString(String texto, String mascara) throws ParseException {
    MaskFormatter mf = new MaskFormatter(mascara);
    mf.setValueContainsLiteralCharacters(false);
    return mf.valueToString(texto);
}
 
开发者ID:ederaa01,项目名称:tecnocar,代码行数:6,代码来源:Rotinas.java

示例12: getHexFormatter

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public static MaskFormatter getHexFormatter(int length) {
    try {
        return new MaskFormatter(Strings.repeat("H", length));
    } catch (ParseException e) {
        log.error("Error creating MaskFormatter", e);
        return null;
    }
}
 
开发者ID:klamann,项目名称:maps4cim,代码行数:9,代码来源:FormattedComponents.java

示例13: ScheduleTimeField

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * @param value the initial value for the widget
 */
public ScheduleTimeField(final LocalTime value) {
  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setTime(value);
}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:17,代码来源:ScheduleTimeField.java

示例14: initialize

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
/**
 * Grafiksel arayuz bilesenlerini olusturup pencereye ekleme isini yapan
 * metot
 */
private void initialize() {
    this.setSize(395, 110);
    this.setTitle("Bir İşlem");
    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    this.getContentPane().setLayout(null);

    // Sayilar arayuze ekleniyor
    this.getContentPane().add(
            createLabel("SAYILAR:", new Rectangle(0, 0, 100, 25)));
    try {
        // Sadece iki basamak kabul eden bicimlendirici
        MaskFormatter ikiBasamak = new MaskFormatter("##");
        // Sadece uc basamak kabul eden bicimlendirici
        MaskFormatter ucBasamak = new MaskFormatter("###");

        // Metin alanlari bicimli metin alani olarak yaratiliyor
        // veri giris hatalarini onlemeye calisiyoruz
        txtSayi1 = new JFormattedTextField(ikiBasamak);
        txtSayi1.setBounds(new Rectangle(100, 0, 30, 25));
        this.getContentPane().add(txtSayi1);
        txtSayi2 = new JFormattedTextField(ikiBasamak);
        txtSayi2.setBounds(new Rectangle(130, 0, 30, 25));
        this.getContentPane().add(txtSayi2);
        txtSayi3 = new JFormattedTextField(ikiBasamak);
        txtSayi3.setBounds(new Rectangle(160, 0, 30, 25));
        this.getContentPane().add(txtSayi3);
        txtSayi4 = new JFormattedTextField(ikiBasamak);
        txtSayi4.setBounds(new Rectangle(190, 0, 30, 25));
        this.getContentPane().add(txtSayi4);
        txtSayi5 = new JFormattedTextField(ikiBasamak);
        txtSayi5.setBounds(new Rectangle(220, 0, 30, 25));
        this.getContentPane().add(txtSayi5);
        txtSayi6 = new JFormattedTextField(ucBasamak);
        txtSayi6.setBounds(new Rectangle(250, 0, 30, 25));
        this.getContentPane().add(txtSayi6);
        // Hedef Sayi arayuze ekleniyor
        this.getContentPane().add(
                createLabel("HEDEF SAYI:", new Rectangle(0, 25, 100, 25)));
        txtHedefSayi = new JFormattedTextField(ucBasamak);
        txtHedefSayi.setBounds(100, 25, 30, 25);
        this.getContentPane().add(txtHedefSayi);
        // Dugmeler ekleniyor
        this.getContentPane().add(getBtnRandomSayi());
        this.getContentPane().add(getBtnRandomHedefSayi());
        this.getContentPane().add(getBtnHesapla());
        // Sonuc ekleniyor
        lblCozum = new JLabel();
        lblCozum.setBounds(0, 50, 300, 25);
        this.getContentPane().add(lblCozum);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:tekrei,项目名称:JavaExamples,代码行数:60,代码来源:BirIslemApp.java

示例15: increaseId

import javax.swing.text.MaskFormatter; //导入依赖的package包/类
public static String increaseId(String id, String mask) throws ParseException {
    LOGGER.info("#### Tools.increaseId id = " + id + " , mask = " + mask);
    MaskFormatter formatter = new MaskFormatter(mask);
    formatter.setValueContainsLiteralCharacters(false);
    String value = formatter.stringToValue(id).toString();
    StringBuilder newValue = new StringBuilder();
    boolean increase = true;
    for (int i = value.length() - 1; i >= 0; i--) {
        char c = value.charAt(i);
        switch (c) {
            case '9':
                newValue.append((increase) ? '0' : '9');
                break;

            case '8':
                newValue.append((increase) ? '9' : '8');
                increase = false;
                break;

            case '7':
                newValue.append((increase) ? '8' : '7');
                increase = false;
                break;

            case '6':
                newValue.append((increase) ? '7' : '6');
                increase = false;
                break;

            case '5':
                newValue.append((increase) ? '6' : '5');
                increase = false;
                break;

            case '4':
                newValue.append((increase) ? '5' : '4');
                increase = false;
                break;

            case '3':
                newValue.append((increase) ? '4' : '3');
                increase = false;
                break;

            case '2':
                newValue.append((increase) ? '3' : '2');
                increase = false;
                break;

            case '1':
                newValue.append((increase) ? '2' : '1');
                increase = false;
                break;

            case '0':
                newValue.append((increase) ? '1' : '0');
                increase = false;
                break;

            default:
                newValue.append(c);
                break;
        }
    }
    return formatter.valueToString(newValue.reverse().toString());
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:67,代码来源:Tools.java


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