ThatGuy
ThatGuy

Reputation: 119

How to scale JPanel to fit JFrame

Currently, I have a full screen JFrame. Within that JFrame, is a panel called MainPanel which is 1280 by 640, a portion of the full screen game. The MainPanel is where my game is rendered to. Is there any way to scale this MainPanel to fit JFrame without having to adjust all the component sizes of sprites and such? I'm thinking of rendering MainPanel to an image and drawing it over JFrame, but I do not know how to go about this.

Thanks.

Upvotes: 0

Views: 772

Answers (1)

FredK
FredK

Reputation: 4084

By default, the layout manager of a JFrame is BorderLayout, and adding a JPanel to it without any arguments will place it in CENTER, which will automatically scale to the size of the JFrame. It will ignore any size you have given the JPanel.

Upvotes: 1

Related Questions