Here's how to fake it:
- Add the PCanvas to the top level JFrame.
- Set the Bounds of the PCanvas to shadow that of a JPanel.
private MainFrame() {
JButton myButton = new JButton("My Button");
JPanel panel2 = new JPanel();
this.add(myButton);
this.add(panel2);
this.add(canvas);
this.setLayout(new BorderLayout());
this.add(myButton, BorderLayout.NORTH);
this.add(panel2, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 400);
setVisible(true);
canvas.setBounds(panel2.getX(), panel2.getY(), panel2.getWidth(), panel2.getHeight());
}
JButton myButton = new JButton("My Button");
JPanel panel2 = new JPanel();
this.add(myButton);
this.add(panel2);
this.add(canvas);
this.setLayout(new BorderLayout());
this.add(myButton, BorderLayout.NORTH);
this.add(panel2, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 400);
setVisible(true);
canvas.setBounds(panel2.getX(), panel2.getY(), panel2.getWidth(), panel2.getHeight());
}
This post was reposted from http://scottizu.wordpress.com/2013/08/20/how-to-fake-adding-piccolos-pcanvas-to-a-jpanel/, originally written on August 20th, 2010.
No comments:
Post a Comment