Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
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  
  Component.setSize() : Borked?  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline crazyc94

Senior Newbie




I like cheese


« Posted 2006-03-02 05:23:14 »

Ok, so some background info before I get into my dilemma: I'm writing a game in Swing (stupid move, I know, however it's working well and I don't feel like moving it AWT).  It's contained in a JFrame window (not fullscreen).  I'm using Java 1.5 on Windows XP.

Now to my dilemma:

I have an option to resize the window to either a larger or a smaller size.  When I recieve the event to resize the window (I generate it through a custom UI), I use the code:

1  
2  
3  
frame.setSize(newWidth, newHeight);
setSize(newWidth, newHeight);
repaint();


Where frame = top level JFrame for my game.

This code has a tendency to not work.

It resizes the window, however does not paint/resize the component (I'm not sure which, only the part of the component which was visible before is painted after being resized).  I can force it to display the component/my game by resizing the window with the cursor, or by minimizing/restoring it.

When I initally create the window I use the following code:

1  
2  
3  
4  
5  
f.setVisible(true);

Insets i = f.getInsets(); //Get the window borders

f.setSize(Preferences.WIDTH + i.left + i.right, Preferences.HEIGHT + i.top + i.bottom); //Set to the size so that the entire playfield is shown


I have to show the window before I determine it's size so I can get the Insets (instead of useless garbage).  When I first start up my game, the window is resized to the proper size, however the component inside isn't.

I have tried adding a frame.pack() in the first code segment before the repaint() (I have also tried using frame.repaint()), however the pack() statement completely discards the size I give it and sets it to a little box (I think the minimum window size in XP).

I have looked/tried to use setMinimumSize() and setMaximumSize(), and wasn't able to get any results (well, actually, lack of change would be more accurate...  Undecided)

If someone could tell me what I've missed here, I would greatly appreciate it.

Also, I tried this exact code on 1.6, and it worked perfectly.  The javadocs mention no change in those methods from 1.5 to 1.6 (at least not that I could find).

Quack!  I'm a duck!

"Or make your own RationalNumber class (unless you need irrational numbers, then you're screwed )." - shmoove
Offline crazyc94

Senior Newbie




I like cheese


« Reply #1 - Posted 2006-03-02 05:44:56 »

Ok, well I managed to find a way to fix it.

I headed back into the javadocs and found this cool little method validate().  I snuck that in before the repaint() and after the setSize(newWidth, newHeight), and now it works perfectly  Grin  Cool

Quack!  I'm a duck!

"Or make your own RationalNumber class (unless you need irrational numbers, then you're screwed )." - shmoove
Offline bytor39

Junior Newbie





« Reply #2 - Posted 2006-03-07 05:51:43 »

I can sympathize.  Swing is riddled with inconsistincies and 'gotchas'.  Hopefully Mustang will fix all of this.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #3 - Posted 2006-03-07 11:18:09 »

err how is that differend in awt?
besides whats wrong with a BorderLayout?

I have to have a look at 1.6 does setSize() invalidate the components these days?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2006-03-07 23:19:35 »

I can sympathize.  Swing is riddled with inconsistincies and 'gotchas'.  Hopefully Mustang will fix all of this.

Validate is far from inconsistant. Its a core part of the render system as AIR pretty well documented.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

BurntPizza (22 views)
2014-09-19 03:14:18

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

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

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

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

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

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

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

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

Longarmx (38 views)
2014-09-07 01:10:19
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!