Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (672)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
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 1404 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:

frame.setSize(newWidth, newHeight);
setSize(newWidth, newHeight);

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:


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

f.setSize(Preferences.WIDTH + i.left + i.right, Preferences.HEIGHT + + 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 Devvie

Medals: 1


« 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!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (45 views)
2016-04-18 14:18:53

KaiHH (45 views)
2016-04-18 08:35:41

KaiHH (75 views)
2016-04-15 12:43:58

theagentd (76 views)
2016-04-14 02:16:17

theagentd (90 views)
2016-04-14 02:15:43

IanParcs (104 views)
2016-04-12 03:51:16

IanParcs (47 views)
2016-04-12 03:50:03

IanParcs (43 views)
2016-04-12 03:49:54

IanParcs (38 views)
2016-04-12 03:49:52

IanParcs (48 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 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‑
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!