Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to expose processFocusEvent when JFormattedTextField is already opened?

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the Netbeans IDE, the JFormattedTextfield has been already created in the method called initComponents();
Therefore I cannot change it. I want to expose and override the method called processFocusEvent.
Any ideas I can do this after the control is created by the IDE wizard.
Thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:I am using the Netbeans IDE, the JFormattedTextfield has been already created in the method called initComponents();
Therefore I cannot change it. I want to expose and override the method called processFocusEvent.
Any ideas I can do this after the control is created by the IDE wizard.
Thanks
Jack


Anyone?
Thanks
Jack
 
Campbell Ritchie
Sheriff
Pie
Posts: 50248
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop using the IDE wizard.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Stop using the IDE wizard.


But I have invested in it a lot and it needs a great deal of work to restart again which I don't really want.
Are there any alternatives?
Thanks
Jack
 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used the GUI wizard so don't know what features it has but one of the following may work:

1. Find a wizard feature that allows you to specify a method(s) in the the component to override.
2. Create you own component by extending JFormattedTextfield and override the method(s) you want to. Then add this custom component via the wizard.
3. Edit the code generated by the wizard. Note the generated code is probably hard to read and once edited you won't be able to use the wizard again so try to avoid this option.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50248
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with option 3 is that once you have used the wizard it may come back and return the code to its original state, so all your edits go walkies.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:1. Find a wizard feature that allows you to specify a method(s) in the the component to override.

Right-click -> Customize code -> select Custom creation
 
Campbell Ritchie
Sheriff
Pie
Posts: 50248
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brilliant, Darryl
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Brilliant, Darryl


Not really. Custom creation code has been available at least since NetBeans 5.5, the first version I used. And since I too started with the misconception that a visual designer could make things easier, I searched around and discovered the provision the first time I needed to override paintComponent(...).

I still maintain that learning to use the visual designer effectively is only worthwhile for those who plan to make GUI design their career. For the rest of us, it's more trouble than it's worth.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am getting some wield behavior,
Custom component


Event Handler

I found that it is now okay to accept blanks, but if CheckDate returns false to it, it doesn't revert.

Secondly

This method doesn't throw at all when the input is 20/20/1992?!

Any suggestions?
Thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas?
Thanks
Jack
 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas?

Please EaseUp. We give our time and experience for free and don't want to feel pressurised into answering questions.


Never check a boolean value == true or false. For true you don't need to do anything and for false append '!' (NOT). Also doesn't getText() return a String, if so you don't need to call toString() on it.
If you want to revert the value you need to either set it back to what it was or configure the JFormattedTextField to REVERT or COMMIT_REVERT on losing focus.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk, please BeForthrightWhenCrossPostingToOtherSites.
https://forums.oracle.com/forums/thread.jspa?threadID=2501502
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic