Results 1 to 8 of 8
- 03-10-2009, 11:01 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
(new to forum) How to make JDialog on top of other always on top windows?
Hi All,
I have a JDialog which is a login screen for my application. There is a common scenario in which this dialog is opened when another application is already running on the screen where said dialog is supposed to appear. That application is always on top.
I'm trying to make my dilaog appear on top of that application, but to no avail. I've tried setAlwaysOnTop(), getFocus() and toFront()
Any suggestions?
Thanks.
- 03-11-2009, 12:18 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
You should better use JFrame instead for it has
statement. It is just in place thing )alwaysontop
JDialog is not as independent as JFrame )
-
To Webuser: I disagree. JDialog also has a setAlwaysOnTop(true) method, and since this the original poster is using this window to function as a dialog, he should not use it as a JFrame.
To the original poster, when I use the method above, it works for me. Code below:
If it doesn't work for you, then either you are doing something different from your code (please post a small compilable program and let us see), or your OS doesn't allow this method to work.Java Code:import java.awt.Dimension; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingConstants; public class AlwaysOnTop { private static final Dimension F_SIZE = new Dimension(300, 300); private static final Dimension D_SIZE = new Dimension(200, 200); private static void createAndShowUI() { JLabel frameLabel = new JLabel("JFrame", SwingConstants.CENTER); frameLabel.setPreferredSize(F_SIZE); JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(frameLabel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); JLabel dialogLabel = new JLabel("JDialog", SwingConstants.CENTER); dialogLabel.setPreferredSize(D_SIZE); JDialog dialog = new JDialog(frame, "JDialog", true); dialog.getContentPane().add(dialogLabel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setAlwaysOnTop(true); dialog.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }
Best of luck.
- 03-11-2009, 05:09 AM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
But author says that JDialog setAlwaysOnTop(true) method hasn't satisfied well enough (
And still JDialog has no EXIT_ON_CLOSE const. Sure you may use System.exit(0) catching JDialog closing. And still there are many ways. But I suggest JFrame for it is more independent. What about lookAndFeel to control top JFrame pane view? )
- 03-11-2009, 10:23 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Thank you everyone for your replies. I'm using a JOptionPane to create my login screen, so I'm actually using both JFrame and JDialog when calling the method loginDialog = pane.createDialog(loginFrame, dialogTitle);
Thing is, how is it detemined which application is on top when both are "always on top"? Is there a way to make the most recently called application to be on top of all the other "always on top apllication"?
Thanks again.
- 03-12-2009, 03:11 AM #6
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
You mean first one is the toppest one?
- 03-12-2009, 09:15 AM #7
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Kinda. I mean that my application can't "beat" the other always on top application and be on top of it. I don't know if it has to do with which application has been activated first, or about properties. Either way, my application is covered by another always on top application eventhough I've used setAlwaysOnTop(true) and such.
- 03-13-2009, 06:07 PM #8
Similar Threads
-
How can I make a program look and feel more windows-like?
By Exhonour in forum New To JavaReplies: 1Last Post: 01-16-2009, 10:15 PM -
setLocation on a JDialog is ignored
By ScottVal in forum AWT / SwingReplies: 7Last Post: 01-13-2009, 07:35 AM -
[SOLVED] How to make a JDialog scrolling from one position to the other.
By Eranga in forum AWT / SwingReplies: 1Last Post: 03-28-2008, 10:26 AM -
Welcome to our new forum: Forum Lobby
By JavaForums in forum Forum LobbyReplies: 18Last Post: 02-07-2008, 05:40 AM -
help with jdialog
By leonard in forum AWT / SwingReplies: 1Last Post: 08-05-2007, 05:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks