Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top