Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jframe content doesn't resize when content pane and canvas are re-sized.  RSS feed

 
David Acline
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if this question is too detailed for this beginner forum or not, but I've had bad luck with people getting all mad at me for posting "improper" or "broad" or "opinion based" questions on stack overflow and the like, so I think posting here is a good bet. And I am a recent high school graduate with not much knowlege about this window stuff, so I think I count as a "beginner" here.

So I'm making this game. My game's native resolution is 256x240, and I want to make the window bigger and scale the game up so it's easier to see. I've been trying to resize my content pane and canvas in my game, and that will make it resize the window, but the actual game will always be drawn in the game's native resolution at the top left of the window, leaving the rest of the window to be just grey empty space. I'm not sure what I should be doing to get it to scale like I want it to, and again I don't know much about this stuff as I'm only a recent high school graduate. I've tried finding the answer and have looked through google for hours and hours, and I've tried looking over the API, but I just can't get an understanding of what I need to do.

Here's what the window is looking like right now:




And here's my entire class that's doing all of the window stuff:




I also haven't figured out how fullscreen works, but I think that comes after this, and I should post another question for that.
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

You have a thing that I see right off that is generally not real good:

you are mixing Swing and AWT components and they are from different eras and not necessarily compatible, there is part of your resize.

Use a JPanel for your display object and override the paintComponent method to display your graphics. There is a discussion in this thread and also further links to another discussion, between the two of them you should be able to get exactly what you need and both threads have code examples that are highly commented.

If that doesn't do it for you, then post more and we'll be glad to help you out.

Les
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are also setting a preferred size on your JFrame and on your Canvas, when you resize your JFrame, either the AWT/Swing difference is causing it to not resize or your Canvas is just staying at it's preferred size because it can. Also once you have everything added into your container, you should do a pack on the JFrame object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!