|
-
Sep 27th, 2001, 01:47 PM
#1
Thread Starter
Member
Really really easy Swing help [resolved]
I'm learning Swing at my mentorship and am used to VB's way of doing GUI stuff, so naturally Swing is hell to me. How can I center a JFrame in the screen, like VB's vbCenterScreen StartupPosition property? I have the VB code but I have no idea how to do it in Java:
VB Code:
Me.Move Screen.Width \ 2 - Me.Width \ 2, Screen.Height \ 2 - Me.Height \ 2
Last edited by filburt1; Sep 27th, 2001 at 03:02 PM.
-
Sep 27th, 2001, 02:25 PM
#2
Dazed Member
I have that code somwhere in one of my programs. Ill have to look for it. Hold on.
-
Sep 27th, 2001, 02:56 PM
#3
Dazed Member
Ok sorry i had to look through some old projects.
This Visual Basic code is equivlent to the Java code
down below.
Private Sub Form_Load()
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
End Sub
// center on display
Dimension display = getToolkit().getScreenSize();
Dimension bounds = this.getSize();
// i used this because my class extended Frame
int x = (display.width - bounds.width) / 2;
int y = (display.height - bounds.height) / 2;
if (x < 0) x = 10; // I forgot why i had these two
if (y < 0) y = 15; // statements, but give them a try.
this.setLocation(x,y);
-
Sep 27th, 2001, 03:02 PM
#4
Thread Starter
Member
Cool, it works.
-
Sep 27th, 2001, 03:03 PM
#5
Dazed Member
the setLocaiton() method is defined in the javax.swing JComponent class along with getLocation(); They are inherited naturally from the java.awt.Component class.
-
Sep 27th, 2001, 03:05 PM
#6
Dazed Member
-
Sep 27th, 2001, 03:09 PM
#7
Thread Starter
Member
*stares blankly* Oh, yeah, I know. Yeah. Right. *continues blank stare*
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
|