Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Button rendered outside Canvas

    This is strange. I set up a test page, put in a canvas, and added a button to the canvas:

    Code:
    public class DiagonalSlitherlink2 implements EntryPoint {
    private Canvas canvas = null;
    
    public void onModuleLoad() {
      canvas = new Canvas();
      canvas.addChild(new Button("Test Button"));
      canvas.setHtmlElement(Document.get().getElementById("gwt"));
      canvas.draw();
    }
    }
    You can see it here:
    https://dev.3dmathpuzzles.com/3dmp/D...therlink2.html

    The button is rendering at the top left of the page instead of within the canvas.

    #2
    I changed it to use a DrawPane:
    Code:
    public void onModuleLoad() {
      drawPane = new DrawPane();
      drawPane.setWidth100();
      drawPane.setHeight100();
      drawPane.setShowEdges(true);
      drawPane.setEdgeSize(1);
      drawPane.setCanDragScroll(true);
      drawPane.setZoomLevel(1.0);
      drawPane.addDrawHandler(new DrawPuzzleHandler());
    
    
      VStack layout = new VStack();
      layout.setWidth100();
      layout.setHeight100();
      layout.addMember(drawPane);
      layout.setHtmlElement(Document.get().getElementById("gwt"));
      layout.draw();
    }
    Here is the DrawPuzzleHandler:
    Code:
    package com._3dmathpuzzles.gwt.client;
    
    import com.smartgwt.client.types.ArrowStyle;
    import com.smartgwt.client.widgets.drawing.DrawLine;
    import com.smartgwt.client.widgets.drawing.DrawPane;
    import com.smartgwt.client.widgets.drawing.Point;
    import com.smartgwt.client.widgets.events.DrawEvent;
    import com.smartgwt.client.widgets.events.DrawHandler;
    
    public class DrawPuzzleHandler implements DrawHandler {
      @Override  
      public void onDraw(DrawEvent event) {
        DrawPane drawPane = (DrawPane) event.getSource();
    
        DrawLine line = new DrawLine();
        line.setDrawPane(drawPane);
        line.setStartPoint(new Point(0,0));
        line.setEndPoint(new Point(100,100));
        line.setLineWidth(1);
        line.setLineColor("#ff0000");
        line.setEndArrow(ArrowStyle.OPEN);
        line.draw();
      }
    }
    I don't see the line or anything on the screen.

    Comment


      #3
      I added a bunch of calls to Window.alert to see where the code is stopping:
      Code:
      public void onModuleLoad() {
      Window.alert("In DiagonalSlitherlink2.onModuleLoad()");
      drawPane = new DrawPane();
      drawPane.setWidth(100);
      drawPane.setHeight(100);
      drawPane.setShowEdges(true);
      drawPane.setEdgeSize(1);
      drawPane.setCanDragScroll(true);
      drawPane.setZoomLevel(1.0);
      Window.alert("Adding drawHandler to drawPane");
      drawPane.addDrawHandler(new DrawPuzzleHandler());
      Window.alert("Back from adding drawHandler to drawPane");
      
      VStack layout = new VStack();
      Window.alert("Created VStack layout");
      layout.setWidth100();
      layout.setHeight100();
      layout.setMembersMargin(0);
      Window.alert("Calling addMember");
      layout.addMember(drawPane);
      Window.alert("Calling VStack.setHtmlElement");
      layout.setHtmlElement(Document.get().getElementById("gwt"));
      Window.alert("Calling layout.draw()");
      layout.draw();
      }
      I get all the alerts up to the line:
      Code:
      layout.addMember(drawPane);
      But it stops after that.

      Comment


        #4
        I saw a forum post that I needed to place the
        Code:
        <inherits name="com.smartgwt.Drawing"/>
        after the
        Code:
        <inherits name="com.smartgwt.SmartGwt"/>
        . Once I did that, I can see the drawing. I missed that.

        Comment


          #5
          A couple of things:

          1) you may not want to use the GWT version of our framework. SmartClient - the JavaScript version - has the exact same APIs laid out in the same way, and then you don't have to install the whole GWT toolchain or deal with the verbosity of Java. We're pointing this out in particular because you seem to be using Window.alert()-based debugging, so you don't seem to be making much use of GWT toolchain

          2) using window.alert()-based debugging, you seemed to uncover a crash the very very slow hard way - you should be looking at our Developer Console and the browser's built-in developer tools, where you would be able to quickly see the cause of the cause

          Comment

          Working...
          X