Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Actual Size of a JFrame?  (Read 1597 times)
0 Members and 1 Guest are viewing this topic.
Offline ToXSiK

Senior Newbie





« Posted 2011-05-24 02:47:25 »

Why when I do:

Quote
gameFrame.setPreferredSize(new Dimension(800, 600));

It gives me a frame about 10 pixels less on the left and the right :/

I have done setSize method as well to no prevail.

How can I fix this so the graphics component embedded in the JFrame is actually 800 x 600

Offline philfrei
« Reply #1 - Posted 2011-05-24 03:08:08 »

Why? Because the size includes the border area. Add a bit for the border edges. I'm not sure how to determine exactly how much. It might change based upon different "look & feels". I usually add 32 to the y-dim (JFrame vs JPanel to display on it).

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #2 - Posted 2011-05-24 03:48:17 »

Call setPreferredSize on the component embedded in the JFrame instead of the JFrame itself.

Then call JFrame.pack().
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ToXSiK

Senior Newbie





« Reply #3 - Posted 2011-05-24 04:20:38 »

Call setPreferredSize on the component embedded in the JFrame instead of the JFrame itself.

Then call JFrame.pack().

I tried that and it didn't work =/

I want it to be exact so if they game were ever to go fullscreen it wouldn't have weird offsets, and I feel like it should fit to the size I specify.  Stupid swing.
Offline Z-Man
« Reply #4 - Posted 2011-05-24 04:59:22 »

Did you set the preferred size of your embedded component, call pack on the JFrame and then do frame.setVisible(true) ? I seem to remember having some difficulty a while ago with the order of things in Swing. This is how I would do it, replacing the JPanel with whatever your embedded component is.
[CODE]
JFrame frame = new JFrame("test");
JPanel panel = new JPanel();
panel.setPrefferedSize(new Dimension(800,600));
frame.add(panel);
frame.pack();
frame.setVisible(true);
[/CODE]
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2011-05-24 04:59:27 »

How about running this code after calling setVisible(true):
1  
2  
Insets i = frame.getInsets();
frame.setSize(width+i.right+i.left,height+i.bottom+i.top);

Offline ToXSiK

Senior Newbie





« Reply #6 - Posted 2011-05-24 05:45:55 »

How about running this code after calling setVisible(true):
1  
2  
Insets i = frame.getInsets();
frame.setSize(width+i.right+i.left,height+i.bottom+i.top);


Genius, thanks!  You should add me on AIM or skype, I seem to run into you a lot Cheesy
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2011-05-24 05:56:00 »

How about running this code after calling setVisible(true):
1  
2  
Insets i = frame.getInsets();
frame.setSize(width+i.right+i.left,height+i.bottom+i.top);


Genius, thanks!  You should add me on AIM or skype, I seem to run into you a lot Cheesy
Haha, glad to help Cheesy

EDIT: Much cleaner code would be to set the preferredSize on the contentPane of the JFrame:
1  
2  
3  
4  
5  
...
frame.getContentPane().setPreferredSize(new Dimension(width,height));
frame.pack();
frame.setVisible(true);
...

Offline philfrei
« Reply #8 - Posted 2011-05-24 06:30:16 »

Ah, "insets" -- so that is how you get the size inside the border area.
Thanks ra4king.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!