|
-
Oct 7th, 2004, 11:06 AM
#1
Thread Starter
Addicted Member
Creating a Frame of an exact size
Hello all,
I'm creating a simple Frame object by extending it in my own class, and I've set the size using the setSize function, but it turns out the size required by the function has the title bar and border included, does anyone know how to create a window with a client area of, say 500,400? There must be some function the get the sizes of the borders and all, as they can change.
Thanks in advance,
Shel
Last edited by Dilenger4; Oct 7th, 2004 at 05:04 PM.
-
Oct 7th, 2004, 01:39 PM
#2
Dazed Member
Code:
import java.awt.*;
import javax.swing.*;
public class Client{
public static void main(String[] args){
JFrame jf = new JFrame();
jf.setSize(500,400);
jf.setVisible(true);
Dimension size = jf.getSize();
System.out.println(size);
Insets insets = jf.getInsets();
int drawwidth = size.width - insets.left - insets.right;
int drawheight = size.height - insets.top - insets.bottom;
jf.setSize(drawwidth,drawheight);
System.out.println(jf.getSize()); // dimensions without insets
}
}
-
Oct 7th, 2004, 01:55 PM
#3
Dazed Member
This should work. The insets are just added to the original size of the JFrame.
Code:
import java.awt.*;
import javax.swing.*;
public class Client{
public static void main(String[] args){
JFrame jf = new JFrame();
jf.setSize(500,400);
jf.setVisible(true);
Dimension size = jf.getSize();
System.out.println(size);
Insets insets = jf.getInsets();
int insetwidth = insets.left + insets.right;
int insetheight = insets.top + insets.bottom;
jf.setSize(500 + insetwidth,400 + insetheight);
System.out.println(jf.getSize());
}
}
Last edited by Dilenger4; Oct 7th, 2004 at 02:01 PM.
-
Oct 7th, 2004, 04:17 PM
#4
Thread Starter
Addicted Member
Thanks! Works like a dream
-
Oct 7th, 2004, 08:29 PM
#5
Fanatic Member
... or simply Extends from JFrame object
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sample extends JFrame{
public sample(){
setSize(500,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args){
new sample().show();
}
}
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
|