Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Canvas Size Problem  (Read 774 times)
0 Members and 1 Guest are viewing this topic.
Offline novasharp

Junior Member


Medals: 1
Projects: 1


Gamemaker


« Posted 2012-11-26 22:38:06 »

I am having a problem with limiting the size of my canvas.

I am setting it to be 576 by 1024, but it ends up being created wider than it needs to be.

Note: red area = the proper size of the canvas, orange = the actual size of the canvas.



I am using setSize, setMinimumSize, setMaximumSize, and setPreferredSize, but it still shows the canvas as larger than it should be.

Thanks,
novasharp

novasharp
Offline pjt33
« Reply #1 - Posted 2012-11-26 22:56:50 »

What contains it, and what layout manager does that container have?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2012-11-26 22:58:08 »

call frame.pack() right before frame.setVisible(true), and don't alter the frame after that.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline novasharp

Junior Member


Medals: 1
Projects: 1


Gamemaker


« Reply #3 - Posted 2012-11-26 23:31:03 »

I have a JFrame containing it.
The layout is just the default layout.

This is my code for initializing the frame:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
this.width = width;
this.height = height;

Dimension size = new Dimension(width, height);

canvas = new Canvas();      
this.add(canvas);

canvas.setMinimumSize(size);
canvas.setMaximumSize(size);
canvas.setSize(size);
canvas.setPreferredSize(size);
canvas.setBounds(0, 0, width, height);

canvas.setBackground(Color.orange);

this.pack();

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setResizable(false);
setIgnoreRepaint(true);
getContentPane().setIgnoreRepaint(true);

novasharp
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2012-11-26 23:42:14 »

call this.pack() right before this.setVisible(true), and don't alter the JFrame after that.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline novasharp

Junior Member


Medals: 1
Projects: 1


Gamemaker


« Reply #5 - Posted 2012-11-26 23:48:14 »

Ok, thanks, that worked. I could not figure out what was going wrong.

novasharp

novasharp
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2012-11-26 23:50:43 »

Unfortunately, I'm not going to explain it, because it requires knowledge of how Swing works, to the extend that you probably never will need to know, beyond this specific case.

You can switch to hardware acceleration (OpenGL) sooner or later, and all this obscurity disappears. Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline novasharp

Junior Member


Medals: 1
Projects: 1


Gamemaker


« Reply #7 - Posted 2012-11-27 01:27:18 »

Thanks again.
If my game gets complex enough, I will switch over to opengl, but so far, my project is not complex enough to warrant all the graphics code.

novasharp

novasharp
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.

Dwinin (22 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!