aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How can I get the feature ALWAYS_ON_TOP with the swing JFrames. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can I get the feature ALWAYS_ON_TOP with the swing JFrames." Watch "How can I get the feature ALWAYS_ON_TOP with the swing JFrames." New topic
Author

How can I get the feature ALWAYS_ON_TOP with the swing JFrames.

philomina dorai
Greenhorn

Joined: May 21, 2003
Posts: 3
I have the main application window(JFrame).It in turn creates many JFrames , i want the new 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.
thanks.
Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
create a JDialog object and add the compoenents to it and say setVisible(true).
it goes liek this.
JFrame frame =new JFrame();//or your class which extends JFrame.
JDialog dia=new JDialog(frame,false)//modeless dialog.
dia.getConetentPane().add(yourGUIPanel);
dia.setBounds(200,300);
dia.setSize(200,300);
dia.setVisible(true);
frame.setSize(600,600);
frame.setVisible(true);


Sun Certified Java Programmer
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Kumar BT:
create a JDialog object and add the compoenents to it and say setVisible(true).
it goes liek this.
JFrame frame =new JFrame();//or your class which extends JFrame.
JDialog dia=new JDialog(frame,false)//modeless dialog.
dia.getConetentPane().add(yourGUIPanel);
dia.setBounds(200,300);
dia.setSize(200,300);
dia.setVisible(true);
frame.setSize(600,600);
frame.setVisible(true);

This is incorrect. I am not sure if it can be done with a JFrame, but I know with a JInternalFrame it is done like:

You might try it with a JFrame and see what happens. The only problem is the .add() method that you won't have for a JFrame because you can't add a JFrame to anything. You can only setVisible(true);
The only other alternative is to add a WindowListener to the JFrame and anytime it changes focus, call toFront() on the JFrame(s) you need to be on top all the time. Kind of sloppy, but I don't know of any other way.


GenRocket - Experts at Building Test Data
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
He was showing how to do it with a JDialog. The only problem was that modal was not set to true. But his comment line stated that.
JDialog dialog = new JDialog (frame, true);
philomina dorai
Greenhorn

Joined: May 21, 2003
Posts: 3
Thanks for all your spontanteous replies.
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.
thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by philomina dorai:
Thanks for all your spontanteous replies.
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.
thanks.

And if you read my initial response I said

The only problem is the .add() method that you won't have for a JFrame because you can't add a JFrame to anything. You can only setVisible(true);
The only other alternative is to add a WindowListener to the JFrame and anytime it changes focus, call toFront() on the JFrame(s) you need to be on top all the time. Kind of sloppy, but I don't know of any other way.

I am pretty sure you are going to have to go the WindowListener approach.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Paul Stevens:
He was showing how to do it with a JDialog. The only problem was that modal was not set to true. But his comment line stated that.
JDialog dialog = new JDialog (frame, true);

Hince, it is incorrect. Especially as it relates to the main question.
philomina dorai
Greenhorn

Joined: May 21, 2003
Posts: 3
Can anyone tell me what api i should use for the linux operation system to make my window always on top using native code.
eg.in win32 we use setWinPostion() in the native code.
thanks.
[ June 23, 2003: Message edited by: philomina dorai ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I get the feature ALWAYS_ON_TOP with the swing JFrames.