focus gained received twice for the same button  
Author Message
news.verizon.net





PostPosted: 2004-4-14 23:09:00 Top

java-programmer, focus gained received twice for the same button I have two buttons in a JPanel (default FlowLayout), which is nested in a
BorderLaout panel's SOUTH slot. The panel implements a FocusListener, and
I'm using the focus gained event to as follows:

/**
* 1) To ensure the next widget, if it has selectable contents (i.e.,
like a JTextField),
* has it's content completely selected.
* 2) To update the status bar with any tool tip text.
*
* @param event
*/
public void focusGained(FocusEvent event)
{
Component c = event.getComponent();
// debug
getStatusHandler().setStatus(c.getClass().getName());
// displayToolTipText( (JComponent) c);
if(c instanceof JTextField) {
((JTextField) c).selectAll();
}
}

For some reason, when the last button in the panel has the focus, it takes
two tabs to get it off. While there is no visual indication after the first
tab as to where the focus is, the debug trace I put in is displaying that
the Component in the focusGained method is still a JButton. The only
modification I made to the KeyboardFocusManager is to add the ENTER & shift
ENTER keys to the forward and backward traversal keys.

Thanks in advance,

- Eric