Can't you check twice for user action inside the actionPerformer?
No, Swing is event-based so only one component can trigger the ActionEvent
. This means that you will need to place
if (e.getSource() == gtf) {
at an outer level of the if
statement to check the source component (which will be triggered by pressing ENTER)