<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Max Length on JTextField Using DocumentFilter: A Step by Step tutorial</title>
	<atom:link href="http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html</link>
	<description>Swing, SWT and Java Desktop related Technologies</description>
	<pubDate>Tue, 06 Jan 2009 21:32:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Big boobs clips movies free.</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-82</link>
		<dc:creator>Big boobs clips movies free.</dc:creator>
		<pubDate>Sun, 17 Aug 2008 00:49:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-82</guid>
		<description>&lt;strong&gt;Big boobs free movies....&lt;/strong&gt;

Big oiled boobs movies. Boobvision big black boobs movies. Big boobs clips movies free. Free big boobs movies. Big boobs free movies....</description>
		<content:encoded><![CDATA[<p><strong>Big boobs free movies&#8230;.</strong></p>
<p>Big oiled boobs movies. Boobvision big black boobs movies. Big boobs clips movies free. Free big boobs movies. Big boobs free movies&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-70</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 29 Jul 2008 16:45:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-70</guid>
		<description>Yep very true Kaushik there are a few restrictions with using the PlainDocument. In my case it wasn't a big deal but could be if you wanted a more flexible approach.

I've found that once you get your basic approach setup like the examples you give from then on its very easy to add smart functionality to your code to allow various nice gui tricks.</description>
		<content:encoded><![CDATA[<p>Yep very true Kaushik there are a few restrictions with using the PlainDocument. In my case it wasn&#8217;t a big deal but could be if you wanted a more flexible approach.</p>
<p>I&#8217;ve found that once you get your basic approach setup like the examples you give from then on its very easy to add smart functionality to your code to allow various nice gui tricks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kaushik</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-69</link>
		<dc:creator>Kaushik</dc:creator>
		<pubDate>Tue, 29 Jul 2008 16:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-69</guid>
		<description>Steve,
 Thanks for the comment. Yes, writing your own document is another way to achieve this. One small advantage of a document filter might be that ,this can be attached to  multiple components that requires different kinds of documents. Having a subclass of  apart from PlainDocument will mandate that these components should have a PlainDocument attached to them and wouldn't be usable by components that uses other kinds of documents like "HTMLDocument" for example.
Your example of "RegexDocument" was good too.
thanks,
Kaushik</description>
		<content:encoded><![CDATA[<p>Steve,<br />
 Thanks for the comment. Yes, writing your own document is another way to achieve this. One small advantage of a document filter might be that ,this can be attached to  multiple components that requires different kinds of documents. Having a subclass of  apart from PlainDocument will mandate that these components should have a PlainDocument attached to them and wouldn&#8217;t be usable by components that uses other kinds of documents like &#8220;HTMLDocument&#8221; for example.<br />
Your example of &#8220;RegexDocument&#8221; was good too.<br />
thanks,<br />
Kaushik</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-68</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 29 Jul 2008 15:28:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-68</guid>
		<description>On a related note I created a Regex Document a while ago which I use now and again for fields that have tricky formats.

public class RegexDocument extends MaxLengthDocument {

	protected final Pattern pattern;

	/**
	 * Contructor used to construct a document object which pattern matches
	 * strings as typed.
	 * 
	 * @param regex
	 *            pattern to match on typed strings
	 * @param maxLength
	 *            maximum length of full string
	 */
	public RegexDocument(final String regex, final int maxLength) {
		super(maxLength);
		this.pattern = Pattern.compile(regex);
	}


	public void insertString(final int offset, final String str,
			final AttributeSet attr) throws BadLocationException {
		final Matcher matcher = pattern.matcher(str);
		if (matcher.matches()) {
			super.insertString(offset, str, attr);
		} else {
			Toolkit.getDefaultToolkit().beep();
		}
	}

}

I used it with calls like this:

xxxTF.setDocument(new RegexDocument("[a-zA-Z0-9]+", 20));

Steve</description>
		<content:encoded><![CDATA[<p>On a related note I created a Regex Document a while ago which I use now and again for fields that have tricky formats.</p>
<p>public class RegexDocument extends MaxLengthDocument {</p>
<p>	protected final Pattern pattern;</p>
<p>	/**<br />
	 * Contructor used to construct a document object which pattern matches<br />
	 * strings as typed.<br />
	 *<br />
	 * @param regex<br />
	 *            pattern to match on typed strings<br />
	 * @param maxLength<br />
	 *            maximum length of full string<br />
	 */<br />
	public RegexDocument(final String regex, final int maxLength) {<br />
		super(maxLength);<br />
		this.pattern = Pattern.compile(regex);<br />
	}</p>
<p>	public void insertString(final int offset, final String str,<br />
			final AttributeSet attr) throws BadLocationException {<br />
		final Matcher matcher = pattern.matcher(str);<br />
		if (matcher.matches()) {<br />
			super.insertString(offset, str, attr);<br />
		} else {<br />
			Toolkit.getDefaultToolkit().beep();<br />
		}<br />
	}</p>
<p>}</p>
<p>I used it with calls like this:</p>
<p>xxxTF.setDocument(new RegexDocument(&#8221;[a-zA-Z0-9]+&#8221;, 20));</p>
<p>Steve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-67</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 29 Jul 2008 15:18:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-67</guid>
		<description>Why not override the Document the textfield uses rather than the filter ? For instance

public class MaxLengthDocument extends PlainDocument {

	/**
	 * Maximum length of the text
	 */
	private final int maxLength;

	/**
	 * Default constructor.
	 * 
	 * @param maxLength
	 *            the maximum number of characters that can be entered in the
	 *            field
	 */
	public MaxLengthDocument(final int maxLength) {
		super();
		this.maxLength = maxLength;
	}
	
	public void insertString(final int offset, final String str,
			final AttributeSet attr) throws BadLocationException {
		if (getLength() + str.length() &#62; maxLength) {
			Toolkit.getDefaultToolkit().beep();
			return;
		}
		super.insertString(offset, str, attr);
	}

}</description>
		<content:encoded><![CDATA[<p>Why not override the Document the textfield uses rather than the filter ? For instance</p>
<p>public class MaxLengthDocument extends PlainDocument {</p>
<p>	/**<br />
	 * Maximum length of the text<br />
	 */<br />
	private final int maxLength;</p>
<p>	/**<br />
	 * Default constructor.<br />
	 *<br />
	 * @param maxLength<br />
	 *            the maximum number of characters that can be entered in the<br />
	 *            field<br />
	 */<br />
	public MaxLengthDocument(final int maxLength) {<br />
		super();<br />
		this.maxLength = maxLength;<br />
	}</p>
<p>	public void insertString(final int offset, final String str,<br />
			final AttributeSet attr) throws BadLocationException {<br />
		if (getLength() + str.length() &gt; maxLength) {<br />
			Toolkit.getDefaultToolkit().beep();<br />
			return;<br />
		}<br />
		super.insertString(offset, str, attr);<br />
	}</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swing links of the week: July 27, 2008 : Pushing Pixels</title>
		<link>http://www.javaswing.net/max-length-on-jtextfield-using-documentfilter-a-step-by-step-tutorial.html#comment-63</link>
		<dc:creator>Swing links of the week: July 27, 2008 : Pushing Pixels</dc:creator>
		<pubDate>Mon, 28 Jul 2008 17:04:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.javaswing.net/?p=38#comment-63</guid>
		<description>[...] has a number of useful tutorials on using the JTextField and related classes, including the introduction to DocumentFilter to enforce upper limit on the number of characters, auto-conversion to upper [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] has a number of useful tutorials on using the JTextField and related classes, including the introduction to DocumentFilter to enforce upper limit on the number of characters, auto-conversion to upper [&#8230;]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
