Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The story of the Enter and the Tab keys

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In most applications that I have known as a user, the enter and the tab key where the same thing. They both would validate and they both would move to the next focusable object.
However in Java, they are different, one triggers an ActionEvent, while the other triggers a FocusEvent. one stays in the Object while the other moves to the next focusable object.
hmm, which behavior is better? what do you think? and If you want them both to validate and move to the next focusable object, what would you do to make this happen?
The problem I am having with this dilemna, is the validation and work that I am having one JTextfield accomplish.
It is a Textfield that accepts a Date only, not only does it validate that it is a date, but it will then pop up a dialog asking if it is a new Date, a modify of the another date, or cancel. If it is a new Date it adds the date to a JList, if it modifies a date, it modifies the corresponding date in the JList, and if they hit cancel it goes back into the Jtextfield, and not to the next Focusable field.
Here is the code I have tried:
client.slWin.bid.estDateAction(new ActionListener(){
public void actionPerformed(ActionEvent e){
actions.changeEstDate(e, client);
}
});
client.slWin.bid.estDateAction(new FocusAdapter(){
public void focusLost(FocusEvent e){
if (!e.isTemporary()){
actions.changeEstDate(e, client);
}
}
});
I use isTemporary() because I don't want to trigger the action if the user clicks out of the field with their mouse, which they might do before filling in the field completely, and getting into an infinite loop of messages saying "Invalid Date. Re-enter"
any suggestions?
Thanks
Mark Spritzler
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone please help.
Thanks
Mark
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not quite clear what your question is. If you're asking how to get the actionPerformed method to transfer focus, try the following:

Calling transferFocus on a component will shift the focus to the next component.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ACtually your answer is what I was looking for. Thanks
Mark Spritzler
p.s. Have you done this and found that two Components had cursors blinking in them? I get that and I am not sure why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic