當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。