I am currently developing an SWT java application on Windows 7. Usually the application will be minimized, and when there is an event on the serial port the application should m
I found some workaround for the problem, might not be the best solution but works for me. If someone have better solution keep posted. Thanks
Using the method showDesktop() first simulate windows key + D event to show the desktop
private void showDesktop() {
try{
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.keyPress(KeyEvent.VK_D);
robot.keyRelease(KeyEvent.VK_D);
robot.keyRelease(KeyEvent.VK_WINDOWS);
}
catch(Exception e){e.printStackTrace();}
}
Then maximize the shell application
private void bringToFront(final Shell shell) {
showDesktop(); //minimize all the application
Thread.sleep(5000); // here have to wait for some time, I am not sure why
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
if(!shell.getMaximized()){
shell.setMaximized(true);
}
shell.forceActive();
}
});
}