Retaining active program status
I am working on a java based sign in machine solution.
I need to have no other applications able to take the focus
from the running java application.
The problem I have is that requestFocus(), show(), toFront(), don't
truly activate the program on windows xp or Mac OS X.
The program's window is in front but it's title doesn't change color and
on the Mac the menu's don't change to the java app.
I don't want to use the java.awt.Robot class if I can avoid it.
Please Help.
Kevin Charles
Here is my test code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Test extends JFrame{
Test(){
super();
setAlwaysOnTop(true);
addWindowFocusListener(new WindowFocusListener(){
public void windowGainedFocus(WindowEvent we){
printInfo("focus gained");
}
public void windowLostFocus(WindowEvent we){
printInfo("Lost Focus");
askForFocus();
}
});
}
private void printInfo(String where){
System.out.println("****************"+where+"****************");
System.out.println("Window is focus:"+isFocused());
System.out.println("Window is active:"+isActive());
System.out.println("Window is Alwasy on Top:"+isAlwaysOnTop());
System.out.println("Window is focusable:"+isFocusableWindow());
System.out.println("Window is Showing :"+isShowing() );
System.out.println("Window extended State :"+getExtendedState() );
System.out.println("**************************************");
}
private void askForFocus(){
requestFocus();
toFront();
show();
}
public static void main(String [] args){
Test t = new Test();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
t.setBounds(0,0,screenSize.width,screenSize.height);
t.setVisible(true);
}
}

