in mustang we have (partially) fixed problem autotransfer after explicit focus request.
It was a very simple fix: we check if there are pending focus requests and if there are we do
not perform auto focus transfer. However this introduce another problem: suppose we have some
pending focus requests and do not perform focus transfer, but those requests fails and so
focus stuck on the component (which was removed/hidden/disabled). Interesting that if I make the component unfocusable, everything works fine (I suspect because of restoreFocus procedure)
Here is a test which reproduce the problem (it is a simplified one, so it is not enought to fix just this particular test)
====== the test =========
import java.awt.AWTEvent;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class failed_transfer_test {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.out.println(e);
}
}, AWTEvent.FOCUS_EVENT_MASK);
Frame frame = new Frame("test");
frame.setLayout(new GridLayout(3, 1));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
we.getWindow().dispose();
}
});
final Button btn1 = new Button("press me");
frame.add(btn1);
final Button btn2 = new Button("I shouldn't have focus at the end");
frame.add(btn2);
final Button btn3 = new Button("I should have focus at the end");
frame.add(btn3);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
btn2.requestFocusInWindow();
btn2.setVisible(false);
// setFocusable(false) works fine however
// btn2.setFocusable(false);
}
});
frame.pack();
frame.setVisible(true);
}
}