Window#toFront() does not activate JFrame

Hello,
I noticed that the method "Window#toFront()" is not enough to activate a JFrame that is hidden behind other windows/applications. So I imagined the following hack, but wonder if anyone knows about a better way:
private Robot r;
        try {
            r = new Robot();
        } catch (AWTException ex) {
            ex.printStackTrace();
private void activateWindow(JFrame frame) {
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(false);
    Point location = MouseInfo.getPointerInfo().getLocation();
    Point locationOnScreen = frame.getLocationOnScreen();
    r.mouseMove(locationOnScreen.x+100, locationOnScreen.y+10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.mouseMove(location.x, location.y);
}The functionality is needed when clicking an icon in the notification area of the task bar. This should start the swing application only once. When the icon is clicked again, the started application should always activate its main window.
Regards,
André

class SingleInstanceController {
    private boolean result = false;
    private File file = null;
    private ObjectOutputStream oos = null;
    private ObjectInputStream ois = null;
    private ServerSocket server = null;
    private Socket client = null;
    private ArrayList<ApplicationStartedListener> listener = null;
    private String appname = null;
    public SingleInstanceController(File file, String appname) {
        this.file = file;
        this.appname = appname;
        this.listener = new ArrayList<ApplicationStartedListener>();
    public SingleInstanceController(String appname) {
        this(new File(System.getProperty("java.io.tmpdir") + "/923jhakE53Kk9235b43.6m7"), appname);
    public void addApplicationStartedListener(ApplicationStartedListener asl) {
        this.listener.add(asl);
    public void removeApplicationStartedListener(ApplicationStartedListener asl) {
        this.listener.remove(asl);
    public boolean isOtherInstanceRunning() {
        if (!this.file.exists()) {
            return false;
        return sendMessageToRunningApplication(new ClassCheck(this.appname));
    public boolean sendMessageToRunningApplication(final Object obj) {
        this.result = false;
        try {
            this.client = new Socket("localhost", getPortNumber());
            // In einem neuen Thread kommunizieren, um einen Deadlock zu verhindern
            new Thread(new Runnable() {
                public void run() {
                    try {
                        SingleInstanceController.this.oos = new ObjectOutputStream(SingleInstanceController.this.client.getOutputStream());
                        SingleInstanceController.this.ois = new ObjectInputStream(SingleInstanceController.this.client.getInputStream());
                        SingleInstanceController.this.oos.writeObject(obj);
                        SingleInstanceController.this.oos.flush();
                        SingleInstanceController.this.result = SingleInstanceController.this.ois.readBoolean();
                    } catch (IOException e) {
                        SingleInstanceController.this.result = false;
            }).start();
            for (int i = 0; i < 10; i++) {
                if (this.result == true) {
                    break;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
            this.client.close();
            return this.result;
        } catch (IOException e) {
            return false;
    public boolean registerApplication() {
        try {
            if (!this.file.exists()) {
                if (!this.file.getParentFile().mkdirs() && !this.file.getParentFile().exists()) {
                    return false;
                if (!this.file.createNewFile()) {
                    return false;
            BufferedWriter wuffy = new BufferedWriter(new FileWriter(this.file));
            int port = getFreeServerSocket();
            if (port != -1) {
                startServer();
            wuffy.write(String.valueOf(port));
            wuffy.close();
            return true;
        } catch (IOException e) {
            return false;
    protected void messageArrived(Object obj) {
        for (ApplicationStartedListener asl : this.listener) {
            asl.messageArrived(obj);
    protected void applicationStartet() {
        for (ApplicationStartedListener asl : this.listener) {
            asl.applicationStarted();
    protected void foreignApplicationStarted(String name) {
        for (ApplicationStartedListener asl : this.listener) {
            asl.foreignApplicationStarted(name);
    private int getPortNumber() {
        try {
            BufferedReader buffy = new BufferedReader(new FileReader(this.file));
            int port = Integer.parseInt(buffy.readLine().trim());
            buffy.close();
            return port;
        } catch (Exception e) {
            return -1;
    private void startServer() {
        new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        SingleInstanceController.this.client = SingleInstanceController.this.server.accept();
                        if (SingleInstanceController.this.client.getInetAddress().isLoopbackAddress()) {
                            new Thread(new Runnable() {
                                public void run() {
                                    try {
                                        SingleInstanceController.this.oos = new ObjectOutputStream(SingleInstanceController.this.client.getOutputStream());
                                        SingleInstanceController.this.ois = new ObjectInputStream(SingleInstanceController.this.client.getInputStream());
                                        Object obj = SingleInstanceController.this.ois.readObject();
                                        if (obj instanceof ClassCheck) {
                                            if (obj.toString().equals(SingleInstanceController.this.appname)) {
                                                SingleInstanceController.this.oos.writeBoolean(true);
                                                applicationStartet();
                                            } else {
                                                SingleInstanceController.this.oos.writeBoolean(false);
                                                foreignApplicationStarted(obj.toString());
                                        } else {
                                            messageArrived(obj);
                                            SingleInstanceController.this.oos.writeBoolean(true);
                                        SingleInstanceController.this.oos.flush();
                                        SingleInstanceController.this.client.close();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    } catch (ClassNotFoundException e) {
                                        e.printStackTrace();
                            }).start();
                    } catch (IOException e) {
                        e.printStackTrace();
        }).start();
    private int getFreeServerSocket() {
        for (int i = 2000; i < 10000; i++) {
            try {
                this.server = new ServerSocket(i);
                return i;
            } catch (IOException ignore) {
        return -1;
}

Similar Messages

  • HST60: qms$trans_errors.display_messages does not activate error window

    Using qms$trans_errors.display_messages; does not activate the error window. The window is popped but is not activated and no errors are shown. When activating the error window the errors are shown.
    Help needed.

    I have the same problem...
    My scenario is:
    I have a form with one block, a control block that collects data then from a when-button-pressed trigger on a button also on the control block, I call server-side code that updates tables (using the Tapi upd/ins/del procedures) but when a BR error occurs and returns to the form , the error block pops-up but is greyed out, only when I click on the block do the errors appears ok.
    NOTE: this only happens the first time the server code is run any subsequent times the error block displays fine.....
    code in ON-ERROR at form level:
    /* CGAP$TES_SEQUENCE_BEFORE */
    begin
    qms$event_form('ON-ERROR');
    end;
    code in ON-ERROR at block level:
    /* CGAP$OLES_SEQUENCE_BEFORE */
    begin
    qms$event_ctrl_block('ON-ERROR');
    end;
    I tried the sychronize and then moving to the block after the on-error code , but it made no difference.
    Regards David Short.

  • Installation error, "Window installer does not permit updatating of managed advertised product. At least one feature of the product must be installed before applying the update.

    When my downloading until 80%, appear Installation error, "Window installer does not permit updatating of managed advertised product. At least one feature of the product must be installed before applying the update."

    What product and version number are you talking about. Is it a trial version, or is it the full or subscription version. If the latter, activate the product with your S/N or Adobe ID and then do the updates.

  • 4s does not activate

    I have tried several times to activate the new Iphone4s.  Tried using cell server.  Tried connecting to a desktop. Does not seem to trigger the same iphone recognition that my previous iphone does. Does not seem to be any signal bars. Message in the iphone window says "could not activate iphone".

    Are you with AT&T? Their servers overloaded and I'd wait until tomorrow and try again. Have read stories of people on the phone for over an hour with AT&T and not getting far.

  • SUS does not activate Updates

    Hi,
    my SUS in Server 3.1.2 does only show tht there are new Updates, but does not activate nor download them.
    Whats up with that freaky stuff called "Server"?

    If this local configuration is using .local as the DNS domain, then DNS services are incorrectly configured.
    Windows Server used that as a default for a while, unfortunately — that's caused no end of trouble.
    That domain is presently reserved for Bonjour / multicast DNS / mDNS use, and not available for this usage.
    Use of .local for a DNS server is known to cause issues, and is something the Apple network engineers have recommended against.
    If you're going to use a bogus top-level domain, then you'll also want to stay out of .arpa, and probably also out of .com and any other ICANN-sanctioned top-level domain, if you don't have a registration for the domain.  Or (easier, better) reserve a domain for your own internal use.
    Here are details of setting up DNS on OS X Server.

  • Windows update does not work after using System recovery disk

    I have a Toshiba Satellite c655 with WIndows 7 64 bit Home premium. The hard drive died on it, so I purchased a new hard drive and purchased the appropriate Recovery media from Toshiba. I followed the directions and installed the 3 disks on to the new hard drive. But Windows update does not work I get the following error: Windows update can not currently check for updates, because the service is not running. You may need to restart your PC    No matter what I try, I can not get it to work. And it will not let me install Windows Defender either. Any ideas or help would be appreciated. Thank you in advance for your time on this matter.
    Solved!
    Go to Solution.

    I get errors saying A problem is preventing the troubleshooter from starting.
    That makes two similarities to the following thread. Both Windows Update and Troubleshooters fail to work correctly.
       Trouble with reinstall of Win7 64 on a L505-ES5018
    The fix was to install a new hard disk driver.
       Intel Rapid Storage Technology
    -Jerry

  • TS1538 I am using windows 7 and my 3rd gen nano is not recognized in itunes. I have followed all online troubleshooting to no avail. My ipod is recognized by windows but does not appear in itunes.

    I am using windows 7 and my 3rd gen nano is not recognized in itunes. I have followed all online troubleshooting to no avail. My ipod is recognized by windows but does not appear in itunes.

    not recognized by anything: http://support.apple.com/kb/TS1369
    recognized by windows, but not itunes: http://support.apple.com/kb/TS1363
    solving the problem if the above does not work:http://www.instructables.com/id/What-to-do-when-iTunes-does-not-recognize-your-i Po/step1
    (make sure you go to the next slides.

  • Windows 8 does not recognize ipod nano anymore

    Windows 8 does not recognize my iPod nano anymore
    Did so in the past
    Followed all troubleshooting tips on Apple's page
    Any other suggestions

    Hi there catfish1967,
    You may find the troubleshooting steps in the article below helpful.
    iPod not recognized in My Computer and in iTunes for Windows
    http://support.apple.com/kb/ts1369
    -Griff W. 

  • Why windows 8 does not recognize ipod touch model A1367 4th Generation?

    Why window 8 does not recognize ipod touch model A1367 4th generation?  and of course iTunes either.

    See:
    iOS: Device not recognized in iTunes for Windows
    I would start with
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    (it applies to win 8)
    Run this to help if it identifies the cause
    iTunes for Windows: Device Sync Tests
    Have you tried on another computer to help determine if you have a computer or iPod problem?

  • Windows 7 does not recognize ipod 6th gen nano

    Windows 7 does not recognize my device so I can't sync to iTunes. I tried running MSCONFIG, reinstalling iTunes and various different cables, usb ports. Any other suggestions?

    Does the iPod appear in Device Manager when it is connected?
    To access device manager, click Start and then right->click on Computer and choose Manage.
    It might be listed as unknown or under the USB host controllers section.
    B-rock

  • Windows Vista does not see my Ipad but it always did prior to this attempt

    Windows Vista does not see my Ipad, this is a new problem and I have not made any major changes to either my computer or to my Ipad.  I am running Vista 64 as an operating system.  I get the message that windows has an unrecognized USB device.  I checked to see if the Apple Mobility software is running and it was, I reset it, turned off the computer, soft reset the Ipad but still no luck.

    Hi,
    Can you try a different USB port?
    Check out this link just in case.
    http://support.apple.com/kb/HT4049
    Carolyn :-)

  • Windows 8 does not recognise Excite 10

    Windows 8 does not recognise Excite 10. Before win7 done this without any  problems, now win8 looking for drivers! can anybody advice me what to do

    Hi,
    Please download the following program and run it on your Windows 8 machine:
       http://ftp.hp.com/pub/softlib/software12/COL44840/mp-109033-2/hppiw.exe
    You need the printer on your home network.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Windows 8 will not activate with new SSD (second) hard drive

    I added a new SSD drive in the second hard drive bay. I used the HP restoration media to install Windows 8 on the new SSD drive. Windows 8 will not activate. After spending 90 minutes on the phone with HP support (and paying $150), they told me to contact Microsoft. After spending some time with Microsoft, they told me that the Windows product key is being locked by HP, and there is nothing they can do.

    Hi badgerbuzz,
    I have brought your issue to the attention of an appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publically post ( serial numbers and case details).
    If you are unfamiliar with how the Forum's private message capability works, you can learn about that here.
    Regards,
    George
    I work for HP

  • Windows 8 does not see hard drive on Satellite A200

    Windows 8 does not see hard drive on A200.
    How to install?

    > with Vista works fine,
    Does this mean that Vista is still installed or is HDD visible while Vista installation setup?
    Some notebooks HDD controller needs SATA driver in order to be able to install system.
    Sat A200 is a little bit older but I dont think the SATA driver is needed here to install Win 8.
    I guess you didnt any SATA drivers to install the Vista right?
    Set the BIOS to default and try to boot again using Win 8.

  • My new Dell PC running Windows 8 does not recognize my iPad or iPhone. Worked OK for iPhone for months but would not work for new iPad.  I removed /relaoded iTunes and now it won't recognize either iPad or iPhone.

    My new Dell PC running Windows 8 does not recognize my iPad or iPhone. Worked OK for iPhone for months but would not work for new iPad.  I removed /relaoded iTunes and now it won't recognize either iPad or iPhone. Got any suggestions?

    Hi there Lizabethfromaz,
    You may find the troubleshooting steps in the article below helpful.
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/ts1538
    -Griff W. 

Maybe you are looking for

  • Need Help: Web Analysis, Unable to retrieve the data & Security Tab missing

    Hi I'm new to Hyperion (our version: 9.2.1) and we're implementing Hyperion Planning. One of the reporting tools is Web Analysis. I'm trying to create simple grid reporting. but I'm unable to retrieve the data instead the result is "n/a" and The File

  • Creagting connection pools dynamically and bind with TxDataSource

              Hi!           Is there a way I can create a dynamic connection pool and associate it to a DataSource           using weblogic. I know I can't create a datasource dynamically, so are there           any work arounds to bind the dynamically c

  • Where do I put Camera Calibration Profiles?

    Running LR 4.2 64-bit on Windows 7 64-bit.  I"m shooting with a Nikon D300. When I look at an image, in Develop, I have a set of choices for "profiles".  These include Embedded, ACR4.3, ACR 4.4, Adobe Standard, Camera D2X mode 1,2,3, Camera Landscape

  • Firefox preview for pdf files doesn't show certain Cyrillic scripts.

    Since pdf preview support was added in Firefox I can't find a solution for the missing Cyrillic letters in the preview of the pdfs which the software in my company generates. Other pdf software/browsers with preview don't have issues with the Cyrilli

  • How to optimise the size of e-mail size????

    Sorry, I have an Iphone 3 and I had a blackberry previously. 2 question s: 1 - is there a possibility to receive on an other format in order to get it compressed. in fact when I'm in a foreign country I have to pay for the Data and I receive a lot of