• Post Reply Bookmark Topic Watch Topic
  • New Topic

resize component whenever jframe is resizing

 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a game. I'm testing on multiple computers and While i tested it I saw in a different computer which have a different screen that all the size of the components in the JFrame have changed. How can I manage to re-size components when JFrame is re-sizing?

NOTE : I saw multiple threads about this subject and none of them fixed my issue.

Let's put some code to begin with :


I'll explain a bit now.

The character panel is the main character which moves. the danger_1 , danger_2 etc.. are the spikes in the ground.

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you explicitly choose to use the null layout, as you did, that means you're accepting the responsibility of writing code to arrange your components in the frame regardless of its size or shape. If you really want to do that, then your first step should be to design an algorithm which derives the location of each component based on the current size of the frame. Then when the frame's size changes (I believe you can set up a listener which tells you when that happens) your code to resize and reposition the components should be run.

Or if you really don't want to do that, and you want to let the Swing code take care of it for you, then you should choose a suitable layout manager and use that instead. Note that you don't need to just use one layout manager, you can have different layout managers controlling different panels. You might want to have a look at the Oracle tutorial about layout managers (web search keywords: java layout manager tutorial) for more (much more) information about that.

Sorry if I didn't improve on those other threads you mentioned, but since you didn't link to any of them I really couldn't address whatever your problems were with those threads. However if there's something else you'd like to mention about this problem and what you've already considered, feel free to post that here on this forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!