Always On Top Functionality in Java

Hi,
I am opening a HTML file in IE browser from my swing application.But the html page always goes behind the application.I need to implement "Always On Top" functionality for the html page in java / javascript.
any idea please ??
Thanks

Try this code. It should be work on all windows which are inherited from java.awt.Window
* Call this from class consructor
public void initialize() {
TopThread top = new TopThread();
top.start();
* Keep JWindow on top (inner class)
class TopThread extends Thread {
public void run() {
while(true) {
toFront();
* Let 10 milliseconds for other code to execute
try {
Thread.sleep(10);
catch(Exception e) {
// Nothing to do

Similar Messages

  • Setting always on top makes it on top of non java applications.

    Hi all..
    If i set always on top property for my frame then my frame is always on top of all the application.
    While i want the frame to be always on top of my Java application not with other windows or any other application.
    Could you suggest me how to proceed for it.

    Typically an application only has a single JFrame, so it is either active or not.
    If you have child windows related to the main frame that you want to also be active when the frame is active then you use a JDialog and specify the main frame as the owner.

  • JOptionPane show Message Dialog always on top found a Solution

    just thought of a solution for the age old java problem with message boxes / dialogs / input .
    It's funny when you google it you'll find like a million people asking for a solution but none or very few that gives an answer that works.
    this is probly not a new solution but i came up with this yesterday and thought i would "share".
    dunno why the java developers hasnt made a always on top function for this since there seems to be a very high demand for it.
    this hax will hopefully work at all times.
    hope google will find this thread, i searched for a solution yesterday and found none? which is surprising and im a pro googler too.
    import javax.swing.*;
    public class main{
         public static void main(String args[]){
              JFrame j=new JFrame();
              j.setAlwaysOnTop(true);
              j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              j.setVisible(true);
              j.setVisible(false);
              JOptionPane.showMessageDialog(j,"hi");
              System.exit(0);
    }

    I didn't realize it was an "age old problem." The JOptionPane's showXXX methods just show an ordinary modal dialog. If you want to set the alwaysOnTop property of said dialog then you just need to obtain a reference and call the method in question.
    JOptionPane op = new JOptionPane("hi",JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = op.createDialog("Message Dialog");
    dialog.setAlwaysOnTop(true); //<-- this line
    dialog.setModal(true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setVisible(true);No need for an intermediate frame.

  • Has anybody used the WInterface for "on top" functionality successfully?

    Dear Everyone,
    This is a question for anybody who has used the WInterface classes and .dll file. I have downloaded the WInterface.zip file and have extracted it. I have also used the provided classes (particularly WInterface.java) and placed the .dll on the "java.library.path".
    As my path points at C:\j2sdk1.4.0\bin I placed the .dll file into this ...\bin directory. However I have not gained success with any attempts to use these classes. Programs compile fine, however when any attempt is made to refer to the methods in the WInterface an exception is raised.
    The type of exception is UnsatisfiedLinkException. I know this to mean that the JVM cannot find the .dll (in this case) being refered to. However I am sure that the file is in a directory on the class path.
    Somebody out there, amongst you guys, knows how to use the WInterface.
    If you are that somebody please explain to me how you achieved the "always on top" functionality that WInterface provides.
    Any help will be really appreciated. Thanks

    Sorry to bump this old post, but I have the same problem. Can someone show me a simple example of how to use WInterface from including it, to compiling it, and executing it?
    Thanks
    Jon

  • Always on top windows

    How can I make "Always on top" window in Java?
    Thanks

    Hi, i a using jdk1.3 on mandrake linux, how to make Jwindow reside on top of all the other windows, i've tried using the listeners, problem is once the focus moves to any of the child component of the window, the focus listener for Jwindow will not work, even requestFocus on the jwindow doesn't get the focus on the window, i can't take JFrame, (don't want title bar), if any body can help with JNI code on linux to make the Jwindow always on top.
    shivajee

  • Widget always on top

    Hi,
    is there a way to make the widget appear always on top?
    thanks!

    No. The widget does not currently have "Always on top"
    functionality. That would be a good suggestion for our Feature
    Request thread in the General Discussions topic, however.
    ;-)

  • Java Task Bar always on Top

    I need to be able to create my own task bar which is a Frame that will be positioned
    always above the Windows task bar and will never be obscured by the windows of other
    appications (Task Manager accepted).
    I have seen many postings on tis group what explain how to have a frame always on top
    but how can I state where on top with reference to the task bar?
    TIA
    Steve

    I dont want to get rid of the task bar but to be able to create an own window which isn in effect
    an own task bar that sits directly above the existing Task Bar if it is visable or if not, then it sits along
    the bottom of the screen mimicing a task bar but with the controls that I want to provide fo rmy specific
    application.

  • Always on Top Frame

    HI, I have search a lot about Always on Top Frame, but couldn't found the solution of my problem.
    My application has a PropertyWindow, the problem is, I want my PropertyWindow always on Top. Please suggest me which container should I use, because If I use JFrame as a PropertyWindow, another frame is created and windows toolbar have two windows.
    If I use JPanel, I dont found the functionalities like WindowClosing, Settitle etc etc.
    Please help me to get rid of this annoying problem. I want exactly something like JBuilder or Photoshop functionality where property windows are always on top and also seperate with the application.

    But I got this error while using 1.5
    "ConnectionPool.java": cannot access java.lang.Object,bad class file: C:\Program Files\Java\j2sdk1.5.0\jre\lib\rt.jar\java\lang\Object.class,class file has wrong version 49.0, should be 48.0,Please remove or make sure it appears in the correct subdirectory of the classpath. at line 13, column 11
    "DBIdentifier.java": cannot access java.lang.String,bad class file: C:\Program Files\Java\j2sdk1.5.0\jre\lib\rt.jar\java\lang\String.class,class file has wrong version 49.0, should be 48.0,Please remove or make sure it appears in the correct subdirectory of the classpath. at line 12, column 11
    Everything works fine in 1.4
    Please Help
    Thanks

  • Need to make JFrame Always on top.

    I have the main application window(JFrame).It in turn creates many JFrames , i want the newly created JFrames to be set as ALWAYS_ON_TOP , ie even if i click on the the main window,the new JFrames should be always on top similar to Yahoo messenger and MSN messenger.
    Actually i don't want the functionality of "ALWAYS_ON_TOP" with JDialog or JInternalFrame,as both of them will ultimately have their parents as the main JFrame window.
    I want this functionality with JFrames that are created from the main JFrame window.
    Actually i am floating some components of my main JFrame window for which i create a new JFrame window and place that floated component.
    Now this floating JFrame is independent of the main JFrame window ,but i want to set "always on top" for the floating JFrame windows similar to the Yahoo and MSN messengers.

    Try this code. It should be work on all windows which are inherited from java.awt.Window
    * Call this from class consructor
    public void initialize() {
    TopThread top = new TopThread();
    top.start();
    * Keep JWindow on top (inner class)
    class TopThread extends Thread {
    public void run() {
    while(true) {
    toFront();
    * Let 10 milliseconds for other code to execute
    try {
    Thread.sleep(10);
    catch(Exception e) {
    // Nothing to do

  • About "Always on Top" windows

    Hi all,
    My application needs an always on top window and I used a dll written
    by Mitch Goldstein. It works perfectly on jvm 1.3.1, but when I try it
    on jvm1.4.1 which is more popular today than 1.3.1, it just doesn't
    work, without any exceptions.
    Can anybody give some hints? Thanks a lot.
    The "Always on top" package written by Mitch Goldstein with examples
    can be downloaded from the following address:
    http://www.esus.com/javaindex/j2se/jdk1.2/javaxswing/toplevelcontainers/jframe/jframealwaysontop.html

    For JRE 1.3 and above, the following code addresses the issue of having two windows with the same title. The function takes a Frame as a parameter, gets the HWND using the AWT Native Interface, and then calls SetWindowPos. Agreed, this code is far more complicated than smg123's solution, but if there's a chance of two windows having the same title, it's probably better to use this:JNIEXPORT void JNICALL Java_JSystem_setWindowAlwaysOnTop__Ljava_awt_Frame_2Z (JNIEnv *env, jclass cls, jobject frame, jboolean flag)
         typedef jboolean (JNICALL* PJAWT_GetAWT) (JNIEnv*, JAWT*); // Function pointer
         JAWT jawt;
         JAWT_DrawingSurface* jds;
         JAWT_DrawingSurfaceInfo* jdsi;
         JAWT_Win32DrawingSurfaceInfo* jdsi_win;
         HANDLE hAWT;
         HWND hwnd;
         jboolean result;
         PJAWT_GetAWT JAWT_GetAWT;
         LPTSTR buf;
         jclass sys;
         jmethodID home;
         jstring ret;
            // This section of code is needed in order to find jawt.dll
         sys = (*env)->FindClass (env, "java/lang/System");
         home = (*env)->GetStaticMethodID (env, sys, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
         ret = (jstring)(*env)->CallStaticObjectMethod(env, sys, home, (*env)->NewStringUTF (env, "java.home"));
         buf = (LPTSTR)(*env)->GetStringUTFChars (env, ret, NULL);
         strcat (buf, "\\bin\\jawt.dll");
         hAWT = LoadLibrary ((LPCTSTR)buf);
         if (!hAWT) return;
         JAWT_GetAWT = (PJAWT_GetAWT)GetProcAddress(hAWT, "_JAWT_GetAWT@8");
         jawt.version = JAWT_VERSION_1_3;
         result = JAWT_GetAWT (env, &jawt);
         jds = jawt.GetDrawingSurface (env, frame);
         jds->Lock(jds);
         jdsi = jds->GetDrawingSurfaceInfo (jds);
         jdsi_win = (JAWT_Win32DrawingSurfaceInfo *)jdsi->platformInfo;
         hwnd = jdsi_win->hwnd;
         SetWindowPos (hwnd, flag ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
         jds->FreeDrawingSurfaceInfo (jdsi);
         jds->Unlock(jds);
         jawt.FreeDrawingSurface (jds);
         (*env)->ReleaseStringUTFChars (env, ret, buf);
    }Note that you must include jawt_md.h as that's where all the types such as JAWT are declared. You can link statically with jawt.lib, but as it is dangerous to assume the JRE version on the user's system, it's probably a better idea to link dynamically and handle any errors that occur.
    Hope that helps.
    Cheers

  • "Show Desktop" bug forces any program windows to be stuck "Always-on-top"

    What I found under Windows 7, when you use the "Show Desktop" feature (I prefer the ⊞ Win + D shortcut) and then bring all windows back by using it again, some windows behave as if they're glued to the front of the z-order. What this means is, say, I have windows
    A B and C open, with focus on A, hit ⊞ Win +D twice, and now it may happen that if I then want to switch to B or C, either by Alt+Tab or by selecting them on the taskbar, the taskbar shows the highlight, but A stays visible (and usable, it's not just a rendering
    issue) in the foreground.
    Imagine the following situations, all three windows cascading and overlapping:
    A (focus)
    B
    C
    -> ⊞ Win + D
    Desktop (focus)
    -> ⊞ Win + D
    A (focus)
    B
    C
    -> click C on taskbar
    A
    C (focus)
    B
    -> click B on taskbar
    A
    B (focus)
    C
    And so on. Focus means actual input focus, i.e. in second situation, any keyboard typing is sent to window B while window A is in the foreground.
    It does not matter what kind of application; in my current case an instance of Outlook and an instance of Explorer is stuck, while a second instance of Explorer and an instance of Firefox behave normally. This should show that this problem can occur even between
    multiple instances of the same application, and that there are no fancy applications involved that like to pretend they are the most important program and internally force "always on top".
    Showing and unshowing the desktop again doesn't help; in the worst case another window might end up with the "glued to the top of the z-order" too. Between those, I can easily switch, but in order to get a window which still behaves normally on top, I have
    to manually minimize the offending windows.
    The only cure seems to close the offending windows so far, I've not found anything else that helps.
    Could it be that Windows 7 has a bug that can force an ALWAYS_ON_TOP flag
    onto some windows when restoring from "Show Desktop", or am I doing something wrong?
    More information from another user:
    I use win+d. Issue easy to replicate, Win7-64bit-Ultimate.
    The affected windows (any program) seem to be placed into a separate "Z" group. You can place multiple/many windows into this always-on-top state, those in the affected state will function normally in relation to each other with the exception that: - The group
    as a whole is always-on-top of any non-affected window - The whole group is on top of the taskbar. - The whole group does not respond to (context on taskbar) "cascade windows" or similar commands.
    The fact that the affected windows are on top of the taskbar and otherwise function as "special windows" shows that windows 7 has a hidden "feature" of always-on-top that gets applied with Win+D. The feature appears to place windows in a super window state
    that is on top of the taskbar. The normal group remaining behind the taskbar. (When you click the start menu or context menu of the taskbar, the start menu/taskbar comes to the foreground of the always-on-top group, however this does not revert the affected
    windows, only a temporary takeover until you switch to something other than the start menu/taskbar)
    This is key to finding an answer. How do we get windows to unassign the special status or not do the assignment in the first place?

    It appeared to have cleared by closing all windows and restarting. Initially I could not reproduce the error, then after opening all my working windows, I did indeed reproduce it on any window.
    I almost think it could be initialized with something to do with multiple windows of Chrome, and then the show desktop problem will crop up once one window has it. This was because: After messing around some more with a chrome session saver (session buddy)
    and restoring sessions and getting the super state, I restored and closed the window I was in and now I am again at a place where I can not reproduce the error, even in my "work environment" with some 35 chrome tabs in two windows, plus other programs, file
    locations, remote desktops and a second chrome profile with another dozen tabs.
    So, back to square one with finding the actual instigator of the super state phenomenon.
    Once you actually have the super sate issue, the following will reproduce:
    Ok, I am doing this as I type it:
    Open chrome (to view this website), then Notepad, then Calculator, (could be any windows, but for the purpose of demonstration, follow along with me)
    The windows should function normally, overlap your windows so that you can see the edge of all windows and the Z-order is (from front to back):the browser on top, then the calculator, then Notepad (you should be able to see part of the background windows).
    Now, with the browser on top, press win+d, then win+d again.
    Click on Calculator, then your browser, your browser is now stuck in the foreground. Clicking on notepad will bring the focus to notepad, and it will be in front of the calculator, yet it will stay behind the browser, as your browser is in "super state". (many
    arrangements of switching focus after returning from win+d will create the problem, with the exeption of clicking the desktop, I also noticed that I could not get calculator into super state unless it overlapped my chrome browser).
    Again, this does not seem to work until at least one of your windows is affected. We do not know how to get the initial window, only subsequent ones.
    I will post back if I find anything else.
    Let me know if there is anything that develops.

  • JInternalframe always on top instead of overlapping

    Hello guys,
    I have some JInternalFrames but one window paints its content above all, even overlapping frames. The code looks like this:
    package visnav.bachelor.gallery;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Insets;
    import java.awt.ScrollPane;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Vector;
    import java.lang.Math;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.SwingUtilities;
    import javax.swing.border.EtchedBorder;
    import visnav.bachelor.DataLoader;
    import visnav.bachelor.preview.PreviewMap_Ext;
    import visnav.common.Config;
    import visnav.common.DBListener;
    import visnav.common.Options;
    import visnav.common.Photo;
    * The class Gallery adds a window in which all selected Photos (=their
    * thumbnails) can be seen.
    * @author Florian Kratschmann
    public class Gallery extends ScrollPane implements DBListener {
         private static Vector<Photo> selectedPhotos;
         private static Gallery instance;
         public JPanel content = new JPanel(new ModifiedFlowLayout(
                   ModifiedFlowLayout.LEFT, 6, 6));
         public String filename = "";
          * Constructor which creates a new Gallery object.
         public Gallery() {
              selectedPhotos = DataLoader.getInstance().getSelectedPhotos();
              this.updateGUI(selectedPhotos);
         public static Gallery getInstance() {
              if (instance == null)
                   instance = new Gallery();
              return instance;
         public void collectionChanged() {
              selectedPhotos = DataLoader.getInstance().getSelectedPhotos();
              this.updateGUI(selectedPhotos);
         public void selectionChanged() {
              selectedPhotos = DataLoader.getInstance().getSelectedPhotos();
              this.updateGUI(selectedPhotos);
         public void valueChanged() {
              selectedPhotos = DataLoader.getInstance().getSelectedPhotos();
              this.updateGUI(selectedPhotos);
         public void updateGUI(Vector<Photo> data) {
              content.removeAll();
              removeAll();
              for (int i = 0; selectedPhotos.size() > i; i++) {
                   filename = Gallery_Ext.getFileName(selectedPhotos.get(i)
                             .getFileLocation());
                   final int j = i;
                   ImageIcon icon = (new ImageIcon(selectedPhotos.get(i)
                             .getThumbLocation()));
                   if (filename.length() > 15) {
                        filename = filename.substring(0, 15) + "...";
                   JButton thumb = new JButton("<html><p align=\"center\">" + filename
                             + "<br>[" + (i + 1) + "/" + selectedPhotos.size()
                             + "]<br></p></html>", icon);
                   thumb.setContentAreaFilled(false);
                   thumb.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             Gallery_Ext.openMIME(selectedPhotos.get(j)
                                       .getFileLocation());
                   thumb.setVerticalTextPosition(JLabel.BOTTOM);
                   thumb.setHorizontalTextPosition(JLabel.CENTER);
                   thumb.setBorder(new EtchedBorder());
                   thumb.setPreferredSize(new Dimension(140, 140));
                   content.add(thumb);
              add(content);
          * A modified version of FlowLayout that allows containers using this Layout
          * to behave in a reasonable manner when placed inside a JScrollPane
          * Workaround made to fit size of screen on first updateGUI firing
          * @author Babu Kalakrishnan
          * @author Florian Kratschmann
         public class ModifiedFlowLayout extends FlowLayout {
              public ModifiedFlowLayout() {
                   super();
              public ModifiedFlowLayout(int align) {
                   super(align);
              public ModifiedFlowLayout(int align, int hgap, int vgap) {
                   super(align, hgap, vgap);
              public Dimension minimumLayoutSize(Container target) {
                   return computeSize(target, false);
              public Dimension preferredLayoutSize(Container target) {
                   return computeSize(target, true);
              private Dimension computeSize(Container target, boolean minimum) {
                   synchronized (target.getTreeLock()) {
                        int hgap = getHgap();
                        int vgap = getVgap();
                        int w = target.getWidth();
                        if (w == 0) {
                             Dimension size = new Dimension(0, 0);
                             int noOfTn = selectedPhotos.size();
                             try {
                                  size = (Config.getDimension("InternalFrameSize4",
                                            new Dimension(0, 0)));
                                                 if (size.width==0){size.setSize(300, 200);}
                                  int noOfRows = (int) Math.ceil(size.width / 140);
                                  int heightNeeded = (int) ((noOfTn*1.25 / noOfRows) * 140);
                                  size.setSize(140, heightNeeded);
                             } catch (Exception ex) {
                                  ex.printStackTrace();
                                  int peter = 2;
                                  int heightNeeded = ((noOfTn / peter) * 280)+140;
                                  size.setSize(140, heightNeeded + 100);                    
                             return size;
                        } else {
                             // w = Integer.MAX_VALUE;
                             Insets insets = target.getInsets();
                             if (insets == null)
                                  insets = new Insets(0, 0, 0, 0);
                             int reqdWidth = 0;
                             int maxwidth = w - (insets.left + insets.right + hgap * 2);
                             int n = target.getComponentCount();
                             int x = 0;
                             int y = insets.top;
                             int rowHeight = 0;
                             for (int i = 0; i < n; i++) {
                                  Component c = target.getComponent(i);
                                  if (c.isVisible()) {
                                       Dimension d = minimum ? c.getMinimumSize() : c
                                                 .getPreferredSize();
                                       if ((x == 0) || ((x + d.width) <= maxwidth)) {
                                            if (x > 0) {
                                                 x += hgap;
                                            x += d.width;
                                            rowHeight = Math.max(rowHeight, d.height);
                                       } else {
                                            x = d.width;
                                            y += vgap + rowHeight;
                                            rowHeight = d.height;
                                       reqdWidth = Math.max(reqdWidth, x);
                             y += rowHeight;
                             return new Dimension(
                                       reqdWidth + insets.left + insets.right, (int) (y*1.2));
                             // return new Dimension(120, 300);
    }Any idea why it's content is always on top?
    Cheers,
    Flo

    As the title I can have inside a JDesktopPane some JinternalFrame "always on top" compared to one that makes the background?You might get better help by explaining what you want to achieve, rather than how you want to achieve it.
    You can do custom painting in a JDesktopPane, you know.
    db

  • Awesome window manager: How to keep application always on top

    Is it possible to keep media player applications always on top ?
    Following is my current configuration.
    { rule = { class = "Vlc" },
    properties = { floating = true, ontop = true } }
    This is working fine whenever I start application. But problem is, if I go to full screen and come back, ontop flag is unset.
    Is there anyway to fix this ?

    shmibs wrote:
    you could probably do something like
    client.connect_signal("property::fullscreen", function(c)
    if c.class == "mplayer" then
    c.ontop = true
    end
    end)
    i haven't tested this, though, so don't be surprised when it fails
    This is working partially. ie, VLC is keeping ontop propery, but video is not going full screen.

  • How to Create Always on Top Window OR Frame

    hi i m hasan, i m using windows 98, and i want to know that how to create a Window OR Frame, which should remain always on top. In windows 98 by pressing windows+D key hides all windows and dailog boxes. But I want it should remain always on top even if some one press windows+D key it should not be minimized.

    Try this code. It should be work on all windows which are inherited from java.awt.Window
    * Call this from class consructor
    public void initialize() {
    TopThread top = new TopThread();
    top.start();
    * Keep JWindow on top (inner class)
    class TopThread extends Thread {
    public void run() {
    while(true) {
    toFront();
    * Let 10 milliseconds for other code to execute
    try {
    Thread.sleep(10);
    catch(Exception e) {
    // Nothing to do

  • "always on top" in fullscreen mode; disable switching away

    Hi,
    I am trying to write a mode for emacs that will keep out as many distractions as possible.  When activated, I can't switch away from the file I'm working on.
    Unfortunately, I can *easily* switch away from my fullscreen Emacs to my webbrowser or email program, and Gnome notifications appear on my screen on top of the Emacs window.
    Is there a way for me to push a fullscreen Emacs window (what Emacs users call a frame) to the top of the windowing stack and DISABLE SWITCHING AWAY FROM IT, while also stopping other windows from poppint above it in the stack?  I'm using Gnome right now, so something gnome-specific would be great, as would any generic solution for X.  There is an "always on top" option for windows in gnome (I am using the default window manager, whatever it is now -- metacity?  compiz? I don't even know anymore!), but it is disabled for fullscreen windows.  that makes sense, normally, but I would like to suspend some of the computer's functionality when I'm writing. 
    Also:  perhaps this deserves its own thread, but it would be nice if notification windows didn't overlay themselves on top of the window that I make this way.
    Thank you!
    Matt

    Hi,
    You say you're using gnome so the default window manager for that would be mutter. The gnome notifications can be turned off from
    gnome-control-center
      I don't know if that's an acceptable solution for you. As for disabling switching to other windows, I've had look in
    dconf-editor
    org --> gnome --> desktop --> wm --> preferences but I don't think I can much that's relevant there. Would disabling raise-on-click deliver the desired behaviour? Otherwise, you could try seeing whether there is an extension at https://extensions.gnome.org/.
    Hope you find what you're looking for
    Last edited by Chazza (2014-03-15 11:47:37)

Maybe you are looking for