0

I am developing a javafx sketching application. I have created a borderpane and dividing it into three regions:

  1. The first region(top region): for menubar.
  2. The second region(center region): is used as a canvas.
  3. The third region(bottom region): is created to represent toolbar items.

The toolbar includes a group of pens and other items. it has created using pane class.The problem in my application is when I draw on the canvas, the drawn line can overcome its boundary when I drag on mouse, and drawn on toolbar.

So is there another pane (for toolbar items) that is used to hide these drawn lines?

Part of the code:

public Paint(){
     p1 = new BorderPane();
     toolsBar = new Pane();
     freePane = new Pane();
     p1.setBottom(toolsBar);
     p1.setCenter(freePane);
    
   
     toolsBar.setCursor(Cursor.HAND);
     toolsBar.setId("toolsBar");
}

Circle can be drawn in toolbar pane:

enter image description here

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • 2
    Just a guess, but try changing the order of `p1.setBottom()` and `p1.setCenter()`. – James_D Aug 24 '20 at 18:44
  • thank you so much, i have create a circle, and it works, – Osama Azzam Aug 24 '20 at 18:50
  • have a good day James – Osama Azzam Aug 24 '20 at 18:51
  • 3
    [Documentation](https://openjfx.io/javadoc/14/javafx.graphics/javafx/scene/layout/BorderPane.html) says "BorderPane does not clip its content by default, so it is possible that children's bounds may extend outside its own bounds if a child's min size prevents it from being fit within it space.". Changing the order of adding children works fine if the other children are opaque. If there is transparency and you want to clip, then [set a clip](https://openjfx.io/javadoc/14/javafx.graphics/javafx/scene/Node.html#setClip(javafx.scene.Node)) with the clip rectangle bound to the size of the center. – jewelsea Aug 24 '20 at 21:25

0 Answers0