|
-
May 29th, 2006, 10:36 AM
#1
-
May 29th, 2006, 11:10 AM
#2
Lively Member
Re: JFrame and JApplet Center on screen
This should do it:
Code:
JFrame main = new JFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
...(set the size and all that)...
main.setLocation(((screenSize.width / 2) - (main.width / 2)),
((screenSize.height / 2) - (main.height / 2)) );
-
May 29th, 2006, 01:13 PM
#3
Re: JFrame and JApplet Center on screen
 Originally Posted by KGComputers
Hi,
What's the method/code for centering a Japplet or JFrame on a monitor screen when loaded?
Thanks... 
Applets are centered by HTML not by java code
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
May 29th, 2006, 10:04 PM
#4
Lively Member
Re: JFrame and JApplet Center on screen
 Originally Posted by KGComputers
Hi,
What's the method/code for centering a Japplet or JFrame on a monitor screen when loaded?
Thanks... 
I was answering that part, for the JFrame
-
May 30th, 2006, 12:46 PM
#5
Re: JFrame and JApplet Center on screen
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CenterJFrame{
public static void main(String[] a){
JFrame main = new JFrame();
main.setSize(new Dimension(400,500));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//..(set the size and all that)...
main.setLocation(((screenSize.width / 2) - (main.width / 2)),
((screenSize.height / 2) - (main.height / 2)) );
main.setVisible(true);
}
}
Hi, when experimenting your code I got an error message...Am I missing something? Is it the package to import?
Here's the error message..
D:\java programs\swing API\CenterJFrame.java:15: width is not public in java.awt.Component; cannot be accessed from outside package
main.setLocation(((screenSize.width / 2) - (main.width / 2)),
^
D:\java programs\swing API\CenterJFrame.java:16: height is not public in java.awt.Component; cannot be accessed from outside package
((screenSize.height / 2) - (main.height / 2)) );
^
-
May 30th, 2006, 02:45 PM
#6
Lively Member
Re: JFrame and JApplet Center on screen
Oh yeah, sorry about that. The main.width and main.height should be main.getWidth() and main.getHeight().
-
May 31st, 2006, 03:12 AM
#7
-
May 31st, 2006, 02:44 PM
#8
Frenzied Member
Re: [RESOLVED] JFrame and JApplet Center on screen
There was some othe way of doing this, but I honestly don't remember how. If I ever think of it, then I'll post it here.
-
Jun 4th, 2006, 11:50 PM
#9
-
Jun 5th, 2006, 12:32 PM
#10
Re: [RESOLVED] JFrame and JApplet Center on screen
HTML Code:
<applet width="300" height="300" code="applet1.class">
<param name="param1" value="value" />
Please install java
</applet>
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|