Application not appearing in the foreground
Hello,
I am facing a problem when my application is not appearing in the
foreground when launched.
That is, for eg., say I am using Eclipse and I try to launch my
application from Eclipse, depending where I place my mouse cursor in
Eclipse IDE, my application appears as an icon in the toolbar (but
maximized behind) or comes visible on top of all applications.
By default, as a Windows OS behaviour, any application will get
launched and appears as an icon in the task bar if another application
becomes the foreground application. In such a case, If we use Ctrl +
Tab, our application will appear. In this case, we cannot see our
application's window as long as use Ctrl + Tab is used or the icon in
the title bar is clicked.
In the above case, actually the application will be maximized, but will
not be the foreground window. So checks like "is frame maximized" dont
work.
I have programmed using MFC, where there are APIs to make the
application appear in foreground, if it is in the background
Is there a solution to this in Java, to find out if my application is
apparing as icon or maximized but appearing as a background window etc?
My application creates a JApplet with a containing JFrame:
public class MyFrame extends JFrame {
// Constructor
public MyFrame(String title) {
setTitle(title); // Set the window
title
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public class MyApplet extends JApplet {
public static void main(String[] args) {
theApp = new MyApplet(); // Create the application
object
theApp.init(); // ...and initialize it
//window.setVisible(true);
}
public void init() {
window = new MyFrame("Sketcher"); // Create the app window
Toolkit theKit = window.getToolkit(); // Get the window
toolkit
Dimension wndSize = theKit.getScreenSize(); // Get screen size
// Set the position to screen center & size to half screen size
window.setBounds(wndSize.width/4, wndSize.height/4, //
Position
wndSize.width/2, wndSize.height/2); // Size
window.setVisible(true);
}
private static MyFrame window; // The application window
private static MyApplet theApp; // The application
object
}
~Thanks in advance