Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (602)
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  
  JFrame dimensions?  (Read 308 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Posted 2013-12-31 02:46:30 »

I want my next game to have a re sizable window (no external libraries used)

How do I get the size of the interior of the JFrame?
What I mean is, I can get the total width/height of the JFrame "frame" via "frame.getWidth()"

The problem is that I set the size of the frame to be 640 x 480, but when I get the dimensions via the method above, I get 646 x 509.

I can only imagine that the numbers get bigger because of the size of the border of the window.

But I don't want those dimensions, I want the dimensions of what I'm actually drawing on.

I know I could just subtract 6 and 29, but that won't work for every OS.

So how can I get the dimensions I'm looking for?

Thanks.
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #1 - Posted 2013-12-31 03:08:14 »

getInsets().

Though it's less work (and probably more reliable) to draw onto a child Component (JPanel for instance), rather than directly onto the top-level Window.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline nhmllr

Senior Devvie


Medals: 1
Projects: 3


slow and steady...


« Reply #2 - Posted 2013-12-31 03:40:12 »

So how could I get the width and height using the aforementioned frame.getWidth() and the "getInset()" method, because the only variables I see from the Inset are top, bottom, right, and left, and I don't quite see how to use that information. I don't quite understand what to add and subtract.

Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online BoBear2681

JGO Coder


Medals: 19



« Reply #3 - Posted 2014-01-01 05:51:47 »

Abuse's second suggestion is the better approach.  You're rendering to some component you shove into a JFrame, such as a Canvas or JPanel.  Use setPreferredSize(new Dimension(640, 480) to set the size of that component.  Then your drawing surface is 640x480, and you don't have to care about the window's frame size.

On resize events, just grab the new size of the Canvas or JPanel you're rendering on.  Then you can decide whether to stretch your screens to fit, center them, etc.
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!