• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
philomina dorai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic