views:

332

answers:

2

Hi all, Been developing a game for a while, and currently re working the GUI, or at least trying to. Had the massive problem of not being able to resize the frame (without issues), as I didn't understand layout managers very well. A few projects later, and time to come back and do some more on the game, and I hit a problem...

The basic layout of the main frame is, mainPane, containing one gameScrollPane and one controlPanel. The scroll pane is a scroll pane, and the control panel a normal panel. The scroll pane contains the main game panel.

As I wanted the scroll pane to take up most of the screen, with the control panel taking up a small lower area, much the same as many Sim like games, so chose the Border layout for the mainPane. I added the scroll pane and set the constraints CENTER and the control panel added and constriants SOUTH. This didn't show the scroll pane, so I played around trying different constraints, and it seems that only when I set the scroll pane constraint to North, does it display at all.

To demonstrate this, I have created a quick video... http://screenjel.ly/q5RjczwZjH8

As you can see, when I change the value of NORTH to CENTER and re run, it's like its not there!

Bonus points for anyone who can see a clear second problem which I may start another question for after this issue is solved!

I thank you for your time to read this.

Thanks in advance for any ideas or thoughts :)

Rel

+1  A: 

I can't get the video to show. It's been buffering for ages.

My guess would be that the scrollpane is in fact filling the center; it's just your game panel that's not being shown.

Your game panel needs to return reasonable values for getPreferredSize().

Update

Another thing you may want to do is have your game panel implement the Scrollable interface. You can then override getScrollableTracksViewportWidth and ...height to return true so your panel will be forced to the scrollpane's dimensions.

Carl Smotricz
If that were so, the scroll bars should still show, shouldn't they?It returns the dimensions of 1400 by 1000. Is that unreasonable?
Relequestual
Well, the scroll bars will only show if they're activated (set in the policies). But 1400 x 1000 is a reasonable size, and it's probably larger than your GUI so that should force it to be shown. My strong recommendation is to hit us with some source code!
Carl Smotricz
re update: surely though the panel (client), should be bigger than that of the scroll panel, otherwise it would defeat the point? I guess I am not fully understanding what you mean, could you elaborate a bit more please?
Relequestual
I meant that the game panel is bigger than that client (I guessed) and this would force scroll bars to be shown if policy allowed it. If nothing's being shown... well, there's a bug somewhere! I'm afraid your video is not helping, at least not me!
Carl Smotricz
alright, ill hit you with it. I gotta warn you, its a beast... just updating svn... and there. http://code.google.com/p/javahospital/source/browse/#svn/src/PanelsAndFramesThere you will find the 3 relevant java files.
Relequestual
Yup, even when policy is set to ALWAYS for both vertical and horizontal, its still a no show.
Relequestual
I see your code, gonna download and run it... I'll be back soon!
Carl Smotricz
OK... lots of minor breaches of conventions, but those are not deal breakers. However, hospital line 80: gameWindow.setContentPane??? That looks bad. Normally, the CP is left alone. You set the layout manager on the CP and then add your North/Center/South components to it.
Carl Smotricz
I have to confess I am not exactly sure what you mean. I have added you on gtalk if you want to log into your gmail and have a mo? :)
Relequestual
Carl helped me out alot solving this issue, and a further issue I also had with layout. Top marks!
Relequestual
+2  A: 

If you'd posted some code to start with then you might have gotten a really quick answer. Luckily, you posted a link in the comments to the other response.

The setContentPane() stuff is weird, especially after doing some things to it that will then get wiped out. However, that's not your problem.

The issue is that you are adding levelMaker and personMover right to mainPane without any constraints. These will then be blowing away anything you set for CENTER... in this case the previously set gameScrollPane.

That's why you see it for NORTH and not for CENTER.

PSpeed
+1 for finding the "correct" problem, and faster than me too :)
Carl Smotricz
You are correct, however they are JInternalFrame's, and so I don't want them to be constrained, however I do want them to be freely moveable.Any further suggestions?
Relequestual
Then you are doing something odd. I thought it was weird that you were using a JDesktopPane and then setting a border layout to it. You can't have it both ways. Either your JDesktopPane allows JInternalFrames floating around or it only accepts components in a BorderLayout. Do you really mean to be using a completely different window in there somewhere? Maybe a game window that is maximized or something?
PSpeed
Carl helped me out ALOT. Turns out the solution was to remove the "mainPane" and change the game panel to a JDesktoPane.If anyone is interested in this, do contact me for details.
Relequestual