1

Is there anyway in Java to set the resolution of a specific JFrame rather than changing the computer's resolution, meaning that if I have JFrame with a size of 100x100 can I make it so the top left point will be (0,0) and the bottom right will be (50,50)? These points being the coordinates inside the JFrame, for example when using Graphics (java.awt.Graphics).

Thank you.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2503315
  • 13
  • 1
  • 3

1 Answers1

1

Graphics2D has a scale option, look after it in the Javadoc.

In your case, it's simply this:

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D)g;
    g2.scale(0.5, 0.5); // 50% x and 50% y

    // rest of rendering
}
Mordechai
  • 15,437
  • 2
  • 41
  • 82