Java Utililty Methods Swing Text Format

List of utility methods to do Swing Text Format

Description

The list of methods to do Swing Text Format are organized into topic(s).

Method

JFormattedTextFieldbuildIntegerField(int min, int max)

Builds a formatted text field with specified min and max

java.text.NumberFormat numberFormat = java.text.NumberFormat.getIntegerInstance();
NumberFormatter formatter = new NumberFormatter(numberFormat);
formatter.setMinimum(Integer.valueOf(min));
formatter.setMaximum(Integer.valueOf(max));
final JFormattedTextField returnValue = new JFormattedTextField(formatter);
returnValue.setColumns(3);
returnValue.addPropertyChangeListener(new PropertyChangeListener() {
    Border m_originalBorder = returnValue.getBorder();
...
intcheckBoundaryCondition(final int pos, final Position.Bias b0, final Position.Bias[] biasRet, final Element neighboringElement, final boolean isLTR, final boolean toWest, final int start, final int length, final int startParagraph, final int endParagraph, final boolean nextIsLTR)
check Boundary Condition
if (toWest && isLTR) {
    if (pos == startParagraph) {
        return Math.max(0, pos - 1);
    } else if (neighboringElement.getStartOffset() == startParagraph && pos == start && b0 == backward) {
        return Math.max(0, startParagraph - 1);
} else if (!toWest) {
    if (b0 == forward && pos == length) {
...
JFormattedTextFieldcreateFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode)
Create a date formatted text filed
DateFormatter dfDateFormatter = new DateFormatter(dfFormat);
dfDateFormatter.setValueClass(Date.class);
dfDateFormatter.setOverwriteMode(bOverwriteMode);
dfDateFormatter.setCommitsOnValidEdit(true);
JFormattedTextField ftfResult = new JFormattedTextField(dfDateFormatter);
return ftfResult;
MaskFormattercreateFormatter(String s)
create Formatter
MaskFormatter formatter = null;
try {
    formatter = new MaskFormatter(s);
} catch (java.text.ParseException exc) {
    System.err.println("formatter is bad: " + exc.getMessage());
    System.exit(-1);
return formatter;
...
MaskFormattercreateFormatterMask(final String mask)
create Formatter Mask
MaskFormatter maskFormatter = null;
try {
    maskFormatter = new MaskFormatter(mask);
} catch (java.text.ParseException exc) {
    System.err.println("formatter is bad: " + exc.getMessage());
    System.exit(-1);
return maskFormatter;
...
NumberFormattercreateIntegerFormatter(int minimum, int maximum)
create Integer Formatter
NumberFormat format = NumberFormat.getIntegerInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setMinimum(minimum);
formatter.setMaximum(maximum);
formatter.setValueClass(Integer.class);
formatter.setCommitsOnValidEdit(true);
return formatter;
MaskFormattercreateMaskFormatter(final String s)
create Mask Formatter
MaskFormatter formatter = null;
try {
    formatter = new MaskFormatter(s);
} catch (final ParseException e) {
    throw new IllegalArgumentException(e);
return formatter;
StringdataFormatada(Calendar cal)
data Formatada
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
return format1.format(cal.getTime());
ElementfindElementUp(String name, Element start)
find Element Up
Element elem = start;
while ((elem != null) && (!elem.getName().equalsIgnoreCase(name))) {
    elem = elem.getParentElement();
return elem;
intfindMatchingBracket(Element el, int offset)
find Matching Bracket
Document doc = el.getDocument();
if (doc.getLength() == 0 || el.getEndOffset() - el.getStartOffset() == 0)
    return -1;
char c = doc.getText(offset, 1).charAt(0);
char cprime; 
boolean direction; 
switch (c) {
case '(':
...