• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with using JFormattedTextField

 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using JFormattedTextField in my code as follows



The issue I am having here is that when I input any text into the Textfield and then delete it and the focus moves out of the Text field, the previous entered value gets displayed.
Is there any way that I can stop this from occuring.

Please suggest a way to resolve this issue.

Regards
 
Maneesh Godbole
Saloon Keeper
Posts: 11073
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please PostRealCode
As per the code you posted, the numberFormat instance you use with the JFormattedTextField is null
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh,

Is the code



not instantiating the NumberFormat?

Regards
 
Maneesh Godbole
Saloon Keeper
Posts: 11073
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your original code was


As you can see numberFormat was null
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh,

Its been corrected now. Coudl you please help me with the above issue.

Regards
Nirmal
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- right

- JFormattedTextField is overkill for special purposes, for basics in most cases, then is suggested to use plain JTextField with DocumentFilter instead (strongly agree with that)

- but is not required in your case, there is quite simple workaround, by override the (Xxx)Formatter by using your original NumberFormat

- then there are accessible rest or interesting methods, e.g. (Xxx)Formatter#setAllowsInvalid, min, max etc..,

- for example, both versions, is possible to comparing

 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks a lot for the sample.

In the TextField with the formatter factory, can we have the text field as empty (not with any value ) by default.

I tried modifying the example but did not work.

Regards
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we have the text field as empty (not with any value ) by default.

- default property for Formatter, against NPE, never ever, don't to set Xxx.setValue(null) or

- simple demostrations about whats happends with InputMask, and by mixing with JFormattedTextField constants

 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an issue with the above code. I have used the above code as shown here


When I start to type in the numbers 123456 etc, the 0 remains in the Integer position and then the numbers are getting enterd in between.
Is there any thing else that I should be doing here, like use Listeneres for the text field to format the text.

If I start to delete any of the integers, it displaying something else or adds zeroes to the integer part. If all the numbers are deleted the 0.00 gets displayed.

Regards
JFormattedTextField.jpg
[Thumbnail for JFormattedTextField.jpg]
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- add FocusListener

- override focusGained

- put there something like as (pseudocode)

myTextField.requestFocusInWindow();
myTextField.setText(myTextField.getText());
myTextField.selectAll()

all three code lines wrapped into invokeLater
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic