karakal
karakal

Reputation: 321

Setting the application focus to a java-program in Ubuntu/LTSP

We are using LTSP with Thin-Clients. We are using it, to run a Java-Swing-Application. The users should not be able to do anything else, so instead of a Gnome-Session we use a shell-script to start our application.

Nearly everything works perfect but one thing: When the Thin-Client starts, the application starts too but doesn't receive the focus. We have to click once with the mouse inside the application, which is not that good, because the application is designed to be used without a mouse.

I didn't found anything useful, a toFront() on my Main Frame wasn't successful.

Has anyone any better suggestions??

Upvotes: 0

Views: 290

Answers (2)

Thomas
Thomas

Reputation: 17422

You could try to call requestFocus on your JFrame as soon as it becomes visible:

JFrame frame = new JFrame();

frame.addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent e) {
            ((JFrame) e.getSource()).requestFocus();
        }
    });

frame.setVisible(true);

Upvotes: 0

Boris Pavlović
Boris Pavlović

Reputation: 64632

You can use method java.awt.Window#setAlwaysOnTop(boolean) to grab the focus and after the first user interaction reset the alwayOnTop property.

Upvotes: 1

Related Questions