I asked a similar question yesterday however after further research on what I wished to accomplish I have reason to believe that the question answered was inadequate and deserves a new question in itself as the question yesterday would solve a different problem and help others but not my particular problem. Link to previous question here.
What I am trying to accomplish is to set the JFrame's contentPane to the size of 200,200, however after drawing two different rectangles you would notice the obvious difference. Please refer to the SSCCE included and the picture attached.
Simply put, I would like Canvas.getWidth()/getHeight and getContentPane.getWidth()/Height to return my specified size 200,200.
Referenced Picture

SSCCE Example
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
@SuppressWarnings("serial")
public class SSCCE extends Canvas implements Runnable {
private JFrame frame;
private BufferStrategy bufferStrategy;
private Graphics2D graphics;
private boolean running = false;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SSCCE game = new SSCCE();
game.setPreferredSize(new Dimension(200,200));
game.setFocusable(true);
game.setIgnoreRepaint(true);
game.frame = new JFrame("SSCCE");
game.frame.setLayout(new BorderLayout());
game.frame.getContentPane().setPreferredSize(new Dimension(200,200));
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.add(game, BorderLayout.CENTER);
game.frame.pack();
game.frame.setIgnoreRepaint(true);
game.frame.setResizable(false);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}
});
}
public synchronized void start() {
this.createBufferStrategy(2);
bufferStrategy = this.getBufferStrategy();
graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
Thread thread = new Thread(this, "main");
thread.start();
running = true;
}
@Override
public void run() {
while (running) {
graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
graphics.setColor(Color.RED);
graphics.fillRect(0, 0, 210, 210);
graphics.setColor(Color.GREEN);
graphics.fillRect(0, 0, 200, 200);
graphics.setColor(Color.BLACK);
graphics.drawString("Specified Width: 200", 0, 10);
graphics.drawString("Specified Height: 200", 0, 20);
graphics.drawString("Canvas Width: " + getWidth(), 0, 30);
graphics.drawString("Canvas Height: " + getHeight(), 0, 40);
graphics.drawString("Content Pane Width: " + frame.getContentPane().getWidth(), 0, 50);
graphics.drawString("Content Pane Width: " + frame.getContentPane().getHeight(), 0, 60);
graphics.drawString("Red Rectangle = 210,200", 0, 70);
graphics.drawString("Green Retangle = 200,200", 0, 80);
graphics.dispose();
bufferStrategy.show();
}
}
}

