So I'd like to make a Canvas
based Java application. I've extended my main class to Canvas
and I size it in it's constructor.
public CanvasApp() {
Dimension size = new Dimension(640, 480);
setSize(size);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
}
and in the main function, I make a frame for it, like this:
CanvasApp cnv = new CanvasApp();
JFrame frame = new JFrame("");
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(null); //I've tried this
panel.setSize(640,480); //but still doesn't work =(
panel.add(cnv, BorderLayout.CENTER);
frame.setContentPane(panel);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
But the content pane appears 650x490 in size. Why is this?
I've attached a picture too.
Component
with a Swing GUI. Use aJComponent
instead. – Andrew Thompson Feb 8 '12 at 13:43Canvas
notComponent
:) – Rothens Feb 8 '12 at 13:58Canvas
for drawing things? – Rothens Feb 8 '12 at 14:52