Problems with focus-handling!
Hi,
I have a problem with the focus-handling on JInternalFames.
What I want: I want to set the focus on my JIF to the first enabled component like a editable JTextField.
-> I try to get all focusable components in a recursiv method. Than I set the focus to the component in the upper left corner. To determin and react on changes (another JIF is opened) I use a JIF-Listener.
What happened:
- I oppen a new JIF: everything is ok.
- Two or more JIF are oppened and I close one: everythings fine, too. The focus is set on the new selected JIF on the right component.
- Two or more JIF are oppened and I select an other JIF
by clicking to his title-bar: All my methods are done right but component.grabFocus() does not work, the component does not get the focus!
What is the problem! Maybe the component is not shown on screen? How can I solve the problem (I use JIF-Listener)?
Here some piece of code:
Component highest = (Component) m_focusableComponents.elementAt(0);
for(int i = 0; i < m_focusableComponents.size(); i++)
{
Component com = (Component) m_focusableComponents.elementAt(i);
if(highest.getLocationOnScreen().x >= com.getLocationOnScreen().x
&& highest.getLocationOnScreen().y >= com.getLocationOnScreen().y)
{
highest = com;
}
}
String name = highest.toString();
int idx = -1;
if((idx = name.indexOf("JWinLMSButton")) >= 0){
System.out.println("... bin in grabFocus fuer Button!");
JWinLMSButton but = (JWinLMSButton) highest;
but.grabFocus();
System.out.println(but.hasFocus());
}
else if((idx = name.indexOf("JTextField")) >= 0){
JTextField tf = (JTextField) highest;
tf.grabFocus();
System.out.println(tf.hasFocus());
}
else if((idx = name.indexOf("SteppedComboBox")) >= 0){
SteppedComboBox scb = (SteppedComboBox) highest;
scb.grabFocus();
System.out.println(scb.hasFocus());
}
where I call my focus-handling methods:
public void internalFrameActivated(InternalFrameEvent e) {
menubar.setRadioButtonSelected(e.getInternalFrame().getTitle());
resetFocusableComponents();
getFocusableComponents(e.getInternalFrame().getContentPane());
setFocus();
}

