How to Fake Adding Piccolo’s PCanvas to a JPanel

One issue with Piccolo is that typically the PCanvas, which is the main canvas used to draw items on the screen must be attached to the top level JFrame. This might be problematic if you want to have your top level JFrame include several Panels. For instance, you might want a JPanel on the left to be a control panel and the PCanvas to be to the right of that. This is like the popular Paint program in Windows.

Here’s how to fake it:

  1. Add the PCanvas to the top level JFrame.
  2. 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.setLayout(new BorderLayout());
    	this.add(myButton, BorderLayout.NORTH);
    	this.add(panel2, BorderLayout.CENTER);

        setSize(600, 400);

    	canvas.setBounds(panel2.getX(), panel2.getY(), panel2.getWidth(), panel2.getHeight());
About these ads

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s