Reputation: 75
I want to create a custom shape in Java Scene Builder - hexagon. I tried using the "Polygon" option but the only thing I get, is a triangle. Does anyone know how can I edit this? I read somewhere that I should set the shape to "resizeable" but the option in Java Scene Builder is inactive...
I would really appreciate any help!
Upvotes: 0
Views: 7274
Reputation: 362
I've created this class
class Hexagon {
double [] points;
double center;
public Hexagon(double side){
center = getH(side);
points = new double[12];
// X Y
points[0] = 0.0; points[1] = 0.0;
points[2] = side; points[3] = 0.0;
points[4] = side+(side/2); points[5] = center;
points[6] = side; points[7] = center * 2;
points[8] = 0.0; points[9] = center * 2;
points[10] = -side/2; points[11] = center;
}
private double getH(double side) {
return ((sqrt(3)/2)*side);
}
public double [] getPoints(){
return points;
}
}
And you can use it for create a polygon just like this:
Polygon hexagon = new Polygon(new Hexagon(100d).getPoints());
Upvotes: 0
Reputation: 75
I figured it out:
<Polygon fill="DODGERBLUE" layoutX="108.0" layoutY="121.0" stroke="BLACK" strokeType="INSIDE">
<points>
<Double fx:value="-50.0" />
<Double fx:value="30.0" />
<Double fx:value="0.0" />
<Double fx:value="60.0" />
<Double fx:value="50.0" />
<Double fx:value="30.0" />
<Double fx:value="50.0" />
<Double fx:value="-30.0" />
<Double fx:value="0.0" />
<Double fx:value="-60.0" />
<Double fx:value="-50.0" />
<Double fx:value="-30.0" />
</points>
</Polygon>
Upvotes: 3
Reputation: 99
I'm not sure about the scene builder as I've never used it, but if you can't get that working you could do it manually. According to the documentation on polygon you create a polygon with Polygon(double... points)
. This question has a way to get the right points.
Upvotes: 0