Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:18:26+00:00 2026-06-13T04:18:26+00:00

I’m experimenting with some Piccolo to create a zoomable interface. I’m creating a rectangle

  • 0

I’m experimenting with some Piccolo to create a zoomable interface.

I’m creating a rectangle on a canvas with some PText on it. Now when zooming, I want to change the text to something different.

I’ve done this in my initialize:

//
        //specify the current Piccolo PCanvas
        //
        m_canvas = getCanvas();
        m_canvas.removeInputEventListener(m_canvas.getPanEventHandler());
        //m_canvas.addInputEventListener(new ClickAndDragHandler(m_canvas));

        //
        //add nodes to the collection -> adding to the collection = adding to the canvas
        //
        m_nodecollection = new NodeCollection(m_canvas);

        RectangleNode node_links = new RectangleNode();
        node_links.setBounds(10, 10, 500, 500);
        m_nodecollection.addNode(node_links);

        RectangleNode node_rechts = new RectangleNode();
        node_rechts.setBounds(600,10,500,500);
        m_nodecollection.addNode(node_rechts);

        PImage node_arrowLeft = new PImage("left.gif");
        node_arrowLeft.setBounds(600, 550, node_arrowLeft.getWidth(), node_arrowLeft.getHeight());
        m_nodecollection.addNode(node_arrowLeft);

        PImage node_arrowRight = new PImage("right.gif");
        node_arrowRight.setBounds(680, 550, node_arrowRight.getWidth(), node_arrowRight.getHeight());
        m_nodecollection.addNode(node_arrowRight);

        m_nodecollection.connectNodesWithLine(node_rechts, node_arrowRight, true);
        m_nodecollection.connectNodesWithLine(node_rechts, node_arrowLeft, true);


        PText node_text = new PText("Zoomlevel Not Supported");
        node_text.setBounds(180,150, node_text.getWidth(), node_text.getHeight());
        m_nodecollection.connectNodesWithLine(node_links, node_text, true);
        m_nodecollection.addNode(node_text);
        node_links.addChild(node_text);
        node_links.setCollection(m_nodecollection);

Created my own rectangle class with the whole nodecollection and PText as membervar.

public class RectangleNode extends PNode{

    private Rectangle2D m_rectangle;
    private NodeCollection collection;
private PText text;

    public RectangleNode()
    {
        m_rectangle = new Rectangle2D.Double();
    }

    public Rectangle2D getRectangle()
    {
        if(m_rectangle == null)
            m_rectangle = new Rectangle2D.Double();
        return m_rectangle;
    }

    public boolean setBounds(double x, double y, double w, double h)
    {
        if(super.setBounds(x, y, w, h))
        {
            m_rectangle.setFrame(x, y, w, h);
            return true;
        }
        return false;
    }

    public void setCollection(NodeCollection collection)
    {
        this.collection = collection;
    }
        public void setText(PText text)
{
    this.text = text;
}
    public void paint(PPaintContext paintcontext)
    {
        Graphics2D g2 = paintcontext.getGraphics();

        //niet ingezoomd
        if(paintcontext.getScale() <= 0.2)
            g2.setPaint(Color.BLACK);

        //half ingezoomd
        if(paintcontext.getScale() > 0.2 && paintcontext.getScale() < 0.7)
        {

            g2.setPaint(Color.BLACK);

        }

        //volledig ingezoomd
        if(paintcontext.getScale() > 0.7)
        {
            g2.setPaint(Color.RED);
            g2.fill(getRectangle());
            g2.setPaint(Color.BLACK);
            g2.draw(getRectangle());
        }
    }
}

Now, I thought I could change the text like this: text.setText(“Tester”); but It doesn’t work, also when for example settext and then add the node to collection then it displays over the current text with a huge error…

Can someone help me please?

kind regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:18:27+00:00Added an answer on June 13, 2026 at 4:18 am

    Consider posting the whole example as SSCCE, looks like some parts of the code are missing. It is not clear how you actually execute setText.

    It may be easier to compose existing nodes and listen to events fired from camera. Consider the following example that draws a rectangle with some text which gets updated according to a zoom level:

    import java.awt.Color;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    
    import edu.umd.cs.piccolo.PCamera;
    import edu.umd.cs.piccolo.nodes.PPath;
    import edu.umd.cs.piccolo.nodes.PText;
    import edu.umd.cs.piccolo.util.PPaintContext;
    import edu.umd.cs.piccolox.PFrame;
    
    public class TestRectZoom extends PFrame {
        public TestRectZoom() {
            super("TestRectZoom", false, null);
        }
    
        public void initialize() {
            getCanvas().setInteractingRenderQuality(
                    PPaintContext.HIGH_QUALITY_RENDERING);
            getCanvas().setDefaultRenderQuality(
                    PPaintContext.HIGH_QUALITY_RENDERING);
            getCanvas().setAnimatingRenderQuality(
                    PPaintContext.HIGH_QUALITY_RENDERING);
    
            final PPath rect = PPath.createRectangle(100, 100, 200, 200);
            rect.setPaint(Color.GREEN);
            getCanvas().getLayer().addChild(rect);
    
            final PText text = new PText(getZoomLevelString());
            rect.addChild(text);
    
            text.centerFullBoundsOnPoint(rect.getBounds().getCenterX(), rect
                    .getBounds().getCenterY());
    
            getCanvas().getCamera().addPropertyChangeListener(
                    PCamera.PROPERTY_VIEW_TRANSFORM, new PropertyChangeListener() {
                        public void propertyChange(final PropertyChangeEvent evt) {
                            text.setText(getZoomLevelString());
    
                            if (getCanvas().getCamera().getViewScale() > 0.9) {
                                rect.setPaint(Color.GREEN);
                            } else {
                                rect.setPaint(Color.RED);
                            }
                        }
                    });
        }
    
        private String getZoomLevelString() {
            return "Zoom level:"
                    + String.format("%.2f", getCanvas().getCamera().getViewScale());
        }
    
        public static void main(final String[] args) {
            new TestRectZoom();
        }
    }
    

    That’s how the result looks like:

    enter image description here enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.