0

I'm trying to set the shape property of an hbox to a polygon. The following code is within a class that extends Hbox with a constructor that requires a list of points called origPoints.

val polygon = new javafx.scene.shape.Polygon()
origPoints.foreach{case (x,y) => polygon.getPoints.addAll(x,y)}
setShape(polygon)
setStyle("-fx-border-color: red")

Sorry if the syntax is a little different. I am using ScalaFX, but I don't believe that is causing any issues in this case.

For more information: I am making an intractable map of the United States. I have the coordinates mapped out for each state. I would like to have the advantages of using an hbox, such as being able to add children such as text.

Turtle
  • 33
  • 1
  • 6
  • According to [this](https://stackoverflow.com/questions/26850828/how-to-make-a-javafx-button-with-circle-shape-of-3xp-diameter), you should set minSize(); and maxSize(); – SedJ601 Jun 25 '17 at 03:53
  • Thanks, setting min/max size made the hbox have a shape so the borders are showing up. The problem now is that they are all anchored at the top left since I am using an anchor pane as the parent. Any idea how to specify the origin on an hbox by coordinate? Seems like this is getting further away from the intended use of a pane. – Turtle Jun 25 '17 at 14:53
  • Write in an answer for this and accept it, or delete the question. Then do research on your new question. If you can't find the answer to your new question, then start a new thread for that question. – SedJ601 Jun 25 '17 at 15:35

1 Answers1

1

As Sedrick Jefferson pointed out, the minWidth and minHeight need to be set or else the hbox prefers a 0 height/width. I wanted my countries to be able to scale when the window was resized so I binded their minHeight/minWidth properties to a SimpleDoubleProperty that kept track of the scale ratio of the background in order to scale the height/width accordingly.

origPoints.foreach{case (x,y) => polygon.getPoints.addAll(x,y)}
shape = polygon
styleClass.setAll("country")
minHeight.bind(yScale.multiply(origHeight))
minWidth.bind(xScale.multiply(origWidth))
Turtle
  • 33
  • 1
  • 6