Connecting Tech Pros Worldwide Forums | Help | Site Map

JFrame always on top

Newbie
 
Join Date: Jul 2008
Posts: 5
#1: Jul 7 '08
Whenever I run my GUI, the frame is pinned as the top window ALWAYS even though I never set it to be like that. I even added in setAlwaysOnTop(false) for good measure (it's default false, right?) and my frame is always on top regardless. Any clues?

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args){
  2.          JFrame frame = new JFrame("Pearson Warranty");
  3.          frame.setResizable(false);
  4.          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5.      frame.setAlwaysOnTop(false);
  6.          Dimension screenSize =
  7.                     Toolkit.getDefaultToolkit().getScreenSize();
  8.          frame.setLocation(screenSize.width/2 - (400/2),
  9.                     screenSize.height/2 - (400/2));
  10.  
  11.         // Get additional frame information
  12.          PearsonWarrantyGUIpanel mainPanel = new PearsonWarrantyGUIpanel();
  13.  
  14.          frame.getContentPane().add(mainPanel);
  15.          frame.pack();
  16.          frame.setVisible(true);
  17.       }

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#2: Jul 8 '08

re: JFrame always on top


Hey there!

Try to set the frame's content Layout to adjust positioning.

Stay tuned if that does not help....
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: Jul 8 '08

re: JFrame always on top


Quote:

Originally Posted by Dököll

Hey there!

Try to set the frame's content Layout to adjust positioning.

Stay tuned if that does not help....

That surely doesn't help; @OP: what JVM (and version) are you running?

kind regards,

Jos
Newbie
 
Join Date: Jul 2008
Posts: 5
#4: Jul 8 '08

re: JFrame always on top


Quote:

Originally Posted by JosAH

That surely doesn't help; @OP: what JVM (and version) are you running?

kind regards,

Jos

1.5.0_15

and since I need to enter 20 characters I have written this line :P
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#5: Jul 8 '08

re: JFrame always on top


Quote:

Originally Posted by jrobinson3k1

1.5.0_15

and since I need to enter 20 characters I have written this line :P

Strange; my Java versions don't show that "always on top" behaviour and they
shouldn't; any chance for an upgrade? (1.6)

kind regards,

Jos
Newbie
 
Join Date: Jul 2008
Posts: 5
#6: Jul 9 '08

re: JFrame always on top


Quote:

Originally Posted by JosAH

Strange; my Java versions don't show that "always on top" behaviour and they
shouldn't; any chance for an upgrade? (1.6)

kind regards,

Jos

I'm also running this program on a Windows 98 machine if that has anything to do with it, but it shouldn't
Newbie
 
Join Date: Jul 2008
Posts: 5
#7: Jul 9 '08

re: JFrame always on top


OK, well I fixed my problem...sorta. Check this out.

When I compile and run my program from command line the window ALWAYS stays on top (the problem I've been having).

Now, I condensed all my files into a jar file and poof! Problem has disappeared. I was planning on eventually making my program a java executable anyway, so as long as it works like this, then I'm happy. But its still odd that when I run it from command line the window is always on top.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#8: Jul 10 '08

re: JFrame always on top


Quote:

Originally Posted by jrobinson3k1

OK, well I fixed my problem...sorta. Check this out.

When I compile and run my program from command line the window ALWAYS stays on top (the problem I've been having).

Now, I condensed all my files into a jar file and poof! Problem has disappeared. I was planning on eventually making my program a java executable anyway, so as long as it works like this, then I'm happy. But its still odd that when I run it from command line the window is always on top.

I find this a bit strange; it is as if the properties of the command window are
inherited by your JFrame; but then again, it shouldn't inherit those things.

What happens if you run your program from a command line window using either
java.exe and javaw.exe? The last one doesn't open another console while the
first one does so.

Or maybe it's MS Windows 98 itself ...

kind regards,

Jos
Newbie
 
Join Date: Jul 2008
Posts: 5
#9: Jul 10 '08

re: JFrame always on top


So the problem seems to be with the Windows 98 console I suppose, because same problem with java, but problem gone with javaw.

Isn't it great how computers always make sense? >_<
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#10: Jul 10 '08

re: JFrame always on top


Quote:

Originally Posted by jrobinson3k1

So the problem seems to be with the Windows 98 console I suppose, because same problem with java, but problem gone with javaw.

Isn't it great how computers always make sense? >_<

Does running java.exe open a new console or is your java program just able to
print in the currently opened console? What does javaw.exe do when you run it
in an already opened console?

I'm afraid we have to point to MS Windows 98 for this all; I can't prove it because
I don't run that blasphemy of an OS.

kind regards,

Jos

ps. MS Windows: a 32 bit graphical shell for a 16 bit patch to an 8 bit operating
system, written for a 4 bit processor, developed by a 2 bit company that can't
stand 1 bit of competition ;-)
Reply