Front window

My application may have any number of opened JFrames. Is there a way to determine which frame is currently the front most frame of a particular type?
I tried tracking window events and focus events, but I may need to find a window that has not recently become active or gained focus.

Why not use JDialogs rather than the JFrames? They seem more natural for this. Anyways, focus listeners seem to work for me:
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
class OpenWindows
    private JPanel mainPanel = new JPanel();
    private JDialog[] dialogs = new JDialog[10];
    private Window topWindow = null;
    public OpenWindows(JFrame pFrame)
        final JFrame frame = pFrame;
        frame.setName("main frame");
        MyFocusListener focusListener = new MyFocusListener(this);
        frame.addWindowFocusListener(focusListener);
        mainPanel.setPreferredSize(new Dimension(200, 200));
        for (int i = 0; i < dialogs.length; i++)
            dialogs[i] = new JDialog(frame, "Dialog " + i, false);
            dialogs.setName("Dialog " + i);
dialogs[i].addWindowFocusListener(focusListener);
dialogs[i].setPreferredSize(new Dimension(200, 200));
dialogs[i].pack();
dialogs[i].setLocationRelativeTo(null);
dialogs[i].setVisible(true);
public JPanel getMainPanel()
return mainPanel;
public void windowOnTop()
System.out.println(topWindow.getName());
private class MyFocusListener implements WindowFocusListener
private OpenWindows openWindow;
public MyFocusListener(OpenWindows openwindows)
this.openWindow = openwindows;
public void windowGainedFocus(WindowEvent we)
topWindow = we.getWindow();
openWindow.windowOnTop();
public void windowLostFocus(WindowEvent arg0)
private static void createAndShowGUI()
JFrame frame = new JFrame("OpenWindows Application");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new OpenWindows(frame).getMainPanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI();

Similar Messages

  • Is there a way to create an action or keyboard shortcut to set Crop tool to the front window size?

    Is there any way to create an action or keyboard shortcut to set the Crop tool to the front window size in Photoshop CS6?
    I find that I use that several times a day. I got used to it being the top choice in the Crop tool presets menu.
    Thanks.

    It depends on whether you have the cloud version or perpetual license version.
    For the cloud version press  I (eye)
    For the perpectual version press  F

  • Front window desing

    while writing code in block window my block window scrolls right and so is the front window . i want that my fron window shouls not scroll irrespective of the length of the block window. i want to display the controls at specific postion on front window but due to scrolling to right it is not possible at least i could not do it.is there any way to remove scrolling from front window.
    2.i am using config vi in acquiring data. ihave place config vi out of my while loop. i have connected this config vi to a control but every time i need to give channel list is it possible that i can assign the channel list just one time and when ever i start program it takes it automatically.

    There are very few actions on the block diagram that would trigger scrolling of the front panel. Double-clicking on a control or indicator terminal to find the front panel control would do that IF it is otherwise outside the windows boundary. (This often happens if you "create control" or "create indicator" from block diagram items.)
    It is not possible to remove scrolling during an edit session. This is a run mode option.
    For the second question you have at least two options. (1) Make the current values default. (2) replace the controls with diagram constants if you never need to be able to change them at run time.
    LabVIEW Champion . Do more with less code and in less time .

  • Return to front window the image changes back to the first one

    I have two images loaded in sequence. After loading the second
    image, I put the frame into the background. When I open the image
    frame (to the front window), the first image is shown (but not the
    second as expected). Why and how to show the lastest image?
    Thank you.

    I got the problem solved. Looks like that java keeps all the
    panel objects (even if I assign a panel pointer to null, the
    panel object is still in the Panel object pool); and when
    the buried screen is up to the front window again, java
    calls paintComponent() for all panels, and thus the first
    image panel and 2nd image panel, and so on, but with
    the last created image panel' paintComponent() called
    first, and thus creating the illusion that the iamge is
    returned to the original one and not the lastest one.
    So the solution is to use an integer to label the lastest
    imag panel and use if ( == latest) then draw() in
    paintComponent().

  • When my most front window is a safari one and I use the shortcut key "Command N", it opens a new finder window and a new safari window at the same time. Why does it happen?

    When my most front window is a safari one and I use the shortcut key "Command N", it opens a new finder window and a new safari window at the same time. Why does it happen?

    I just found the solution!
    Niel
    Re: Why is my Finder window popping up when I open my Safari window? 
    Jan 20, 2008 7:58 PM (in response to alak)
    Open the General tab of the Safari preferences and correct the home page; the default page is this one. If it has become set to a folder on an FTP server or a local drive, that request will be sent to the Finder. (28252) 
    iMac Late 2007 Core 2 Duo, Mac OS X (10.5.1)

  • Applescript can't get name of front window

    The AppleScript support seems broken or unreliable (at least on OSX 10.10.1).
    For example, this little, very basic script worked in Firefox 33 but now (34?, 35 or 36) NOT anymore:
    tell application "Firefox"
    name of front window
    end tell
    ==>
    error "plugin-container got an error: Can’t get name of window 1." number -1728 from name of window 1
    Hint: If you check the output of the next applescript snippet, you see that the 'windows' don't even get a correct id.
    tell application "Firefox"
    windows
    end tell

    A further hint (tested on firefox version 35 and 36):
    In the script, application 'Firefox' gets replaced by 'plugin-container' when compiling the script !!!

  • Safari auto switches between windows, makes the front window inactive...

    Hi all,
    I'm having a really annoying problem with Safari...
    When I'm browsing quite often the front window kind of deselects itself, say for instance I have a couple of browser windows open and the downloads window, it will automatically bring the downloads window to the front! Meaning I then have to click on the browser window to make it active so I can then continue whatever I am doing... I am not pressing any key commands for this to happen (I know cmd and ~ (tilde) does this as I use it often to switch between windows). It just does it off it's own back, it's like someone else is controlling the window...
    Funnily enough, it's just happened then again! when i'm typing this message, it brought the downloads window to the front and then this one back to the front, in the space of a second or so...
    Thanks in anticipation as this is one **** of an annoying problem!

    HI and Welcome to Apple Discussions...
    Try maintenance...
    From the Safari Menu Bar, click Safari / Empty Cache. When you are done with that...
    From the Safari Menu Bar, click Safari / Reset Safari. Select the top 5 buttons and click Reset.
    Go here for trouble shooting 3rd party plugins or input managers which might be causing the problem.
    http://support.apple.com/kb/TS1594
    And make sure Safari is not running in Rosetta. Right or control click the Safari icon in your Applications folder then click Get Info. In the Get Info window click the black disclosure triangle so it faces down. Where you see Open using Rosetta... make sure that is NOT selected.
    If you still have problems with Safari, go to the Safari Menu Bar, click Safari/Preferences. Make note of all the preferences under each tab. Quit Safari. Now go to ~/Library/Preferences and move this file com.apple.safari.plist to the Desktop. Relaunch Safari. If it's a successful launch, then that .plist file needs to be moved to the Trash.
    Carolyn

  • Losing focus of front window?

    When you hide safari (version 2.0 in conjunction with 10.4) and then return, the front window is not the one you left it with.
    The front window becomes the first window you opened, with the focus remaining on the old front window.
    For example, if you have two windows open (apple.com and bbc.co.uk respectively), hide safari and return, apple.com will be the front window (hiding the other), but when you hit apple-R, the 'back window' (bbc) will refresh.
    Can you fix this - it's really bugging me.

    Hi Ric,
    Despite toby's first post here I can confirm his problem because I have exactly the same problem. And I think there are other people effected by this Focus problem also assuming Toby and I are not the only ones.
    The problem is Exactly as Toby describes in his post. The focused window disappears behind another window, when two or more windows are open, when you return to Safari after a command H to hide the program.
    The focus is still on the same window (which was at the front) when leaving Safari (noticed by the red yellow and green focus buttons top left) BUT the window has moved to the back of the stack, leaving you with a different (unfocused, hence the grey dots) window when you return after a hide command.
    This is extremely annoying and is definitely something having to do with either Tiger (10.4.2/1) or the new Safari because under Panther and Safari 1.3 this problem was not there...
    So help to this bug would be appreciated and passing this bug along to the Safari dev team would also help (I think).
    Thanks .

  • Front window drops back

    I have several windows open. After about five seconds, the front, active window stops being active, so there are no active windows. I can make any window active by clicking on it, but after five seconds it, too, goes in active. What's going on?

    thanks for the group!

  • Always-in-front window

    Hi,
    How can I make a window always being in the front of everything, but leave another "normal" window as the active one?
    Thanks!
    Max

    How can I make a window always being in the front of everything, but leave another "normal" window as the active one?Try using:
    jWindow.setAlwaysOnTop(true);
    //OR
    jFrame.setAlwaysOnTop(true);Thanks!

  • Print front window

    I am using applescript studio.  I am working on a document based application.
    my document has text fields, buttons, switchs and a table.  I want this document to print when the "file-print" menu is chosen.
    By default only the currently selected item is printed.  I want all of the items in the window to print.
    the window i want to print is my applications current window.
    currently I use screencapture to a file and use "Preview" to print.  It works but is uses a shell to operate.  I want a pure applescript method. I want this so when the user says print the print dialog appears and they can choose to "save PDF" or "Preview" or "Fax" or what ever printer options are available.
    I was under the impression that anything drawn to the screen could be drawn to the printer.  I've looked at some cocoa c code that does this using NSview and NSprint objects.  I have seen a few applescript examples that use call method "print:" to print a table, which my project does by default if the table has focus.
     

    Don't search more.
    The properties associated to the Print command (in Applescript) are not functional ;-(
    Yvan KOENIG (VALLAURIS, France) mardi 21 décembre 2010 21:16:02

  • How to invisible LED in cluster from front windows

    Hi guys,
    I have cluster inside array1*8 it has three LEDs, sometimes i need one or two LEDs, so how to invisible extra LED from cluster.
    I knew how invisible some buttons or string...etc. But my question how to invisible inside cluster that is inside array
    Thanks and best regards.

    OK Array of clusters containing "Invisible" controls-
    Since all elements in an array must share all properties except value we need a solution where the value property controls visibility as far as users are concerned.  LEDs (Booleans) are out-
    BUT, if you used Color boxes instead of booleans you can set the value to "LED Off" "LED On" or "Transparent"
    Jeff
    Attachments:
    Control 2.ctl ‏7 KB

  • Displaying the Temp. at different location by selecting in front window tab

    hi,
    i am trying to develop a system to displaying the tempurature as well as control. please find the attached picture file to give a better view regarding my quastion.
    this program contain few tabs.
    page 1- page which is the user will select the location of thermocouples. once the thermocouple location selected, the selected name will be used as a reference in logging TXT file as a header of the coloum. 
    page 2,3,4,5 and 6 - page which will display the selected tempurature
    problem:
    the agilent data logger has only 40 thermocouple logging capability. the system will have about 80 to 90 thermocouple locations. so the user will select different thermocouple location at beginning of the testing for given thermocouple.
    for example:
    if the user select the thermocouple 1 is assign to location T1 - 3 then the reading of thermocouple 1 should display on the page 3 at correct location. on the next test the thermocouple1 could change to T1 - 8.
    this few days i spend good couple of hours on this problem and the solution still some where in the sky!!!! or no solution for this problem.    
    Attachments:
    page 1.jpg ‏192 KB
    page 3.jpg ‏182 KB

    Hello siva,
    here comes an example... (LV7.0)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Select_Indicator.vi ‏21 KB

  • Why doesn't clicking on a Finder window always bring it to the front

    Right now on my screen I have two Finder windows. One is partially covered by the other.
    Clicking on the rear window does not bring it to the front. I've seen this happen many times already.
    Why wouldn't it come to the front and cover the current front window?
    Thanks,
    doug

    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • How to resolve the issue with Finder: "The last time you opened finder, it unexpectedly quit when reopening Windows"

    For anyone who is struggling with this issue that simply will not go away, please try:
    1. Fist turn off the mac
    2. Turn on the mac while holding the shift key (safe mode)
    3. Once all logged in click on Finder at the bottom of your screen
    4. Click on Go 5 steps to the right of the Apple logo
    5. Hold the Alt key and click on Library
    6. Open the Preferences folder
    7. Drag 'com.apple.Finder.plist' to yourDesktop
    7. Restart the mac
    That should hopefully resolve it, if not place the plist file on your Desktop back to its original location. Thank you!

    Do a backup.
    Quit the application.
    Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J.  When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder.  Select Library. Then go to Preferences/com.apple.mail.plist. Move the .plist to your desktop.
    Restart, open the application and test. If it works okay, delete the plist from the desktop.
    If the application is the same, return the .plist to where you got it from, overwriting the newer one.
    Thanks to leonie for some information contained in this.

Maybe you are looking for

  • Project 2013 APP-V Plugin

    Hi, I have a Project 2013 APP-V package created and published successfully. Now I have a requirement from user to add a plugin for Project 2013. I don't want to make this plugin to be available to all users. Any solutions? I thought of creating a con

  • Why do I have two photo libraries?

    I found two photos libraries: I have one on my imac in the "pictures folder" and I also have one on my external drive. All I have done so far is import over my aperture library and re-arranged the projects. Both have the same time stamp today at 3:59

  • Setting session attributes at the Role level

    I am running AM7.1 in Legacy mode and I am trying to create a role and assign session attributes at this role level. I followed the instructions for doing this but it does not seem to be working. I created the role and added the session service to it

  • Code Navigator Issue.

    Hi - I have just installed DW and pasted some web page source code into the main window. The problem is whenever I click any where in the code window I get the code navigator popping up. I tried disabling it as mentioned in the help topic by clicking

  • How to sync kalendar with goolge calendar automatically after upgrading to mountain lion?

    Hello, after upgrading to OS X Moutain Lion on my MacBook Pro the calendar is not automatically syncronised with my google caledar even the account is set up properly. It seems the calendar has no contact at all my google account. It still works on m