Results 1 to 5 of 5
- 11-05-2012, 06:35 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 35
- Rep Power
- 0
limit characters in textfield in swing
I am designing a calculator in which user enters the numbers by clicking a mouse button.
The problem is it takes endless characters and i want to limit the number of input characters to 10.
I tried using "setColumns(10)" to textfield but it does not solve the problem .
Can anyone show me the way to limit number of characters.
-
Re: limit characters in textfield in swing
one way is to use a FormattedTextField. Myself I kind of like using a DocumentFilter as it is quite flexible.
- 11-05-2012, 07:12 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Re: limit characters in textfield in swing
Use Document Listener to your text field.. then override "public void insertUpdate(DocumentEvent E)" method..
in that You will Place Your Condition as textField.getDocument().getLength() is not more than 10.. if entered more than ten U will display any Message Box.. I think it will work for You.
-
Re: limit characters in textfield in swing
No, this is the wrong way to go as it checks the text after it has been added to the textcompoment. Again, much better is to use a DocumentFilter which checks the text before it is added to the component, and so you can delete it, improve it, or otherwise modify it before adding it to the component. The filter is definitely the way to go.
- 11-06-2012, 11:53 AM #5
Member
- Join Date
- Aug 2012
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
swing or awt display text with characters above 0xfffe
By jchip in forum AWT / SwingReplies: 1Last Post: 04-30-2012, 04:28 AM -
How to limit characters textbox in java
By rjagan in forum New To JavaReplies: 11Last Post: 03-28-2011, 10:09 PM -
How to make Swing JTextField look like AWT TextField?
By LeonLanford in forum AWT / SwingReplies: 1Last Post: 09-04-2010, 04:06 PM -
[SOLVED] Turkish Characters in Java desktop Swing applications?
By doganc in forum Advanced JavaReplies: 6Last Post: 03-06-2009, 09:51 PM -
Displaying Chinese characters on Swing components
By vaskarbasak in forum AWT / SwingReplies: 3Last Post: 06-26-2008, 08:27 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks