...
Nyttige figurer er strek (Line), rektangel (Rectangle), sirkel og ellipse (Circle og Ellipse), buesegment (Arc), polygon (Polygon), segmentert figur (Path) og tekst (Text). I tillegg er det en egen klasse for bilder (ImageView som viser et Image, som ikke er en Shape). Noen av disse er vist i ekesemplet under, hvor center-regionen er fylt med et Pane-objekt med noen figurer i, med ulike grafiske effekter.
Code Block |
---|
| @Override
public void |
@Override
public void start(Stage stage) throws Exception | {
BorderPane root = new {
BorderPane root = new BorderPane(); // Root of the scene | graph
graph
// Add one Text node in each surrounding region
root.setTop(new Text("top")); |
root.setBottom(new Text("bottom")); |
root.setLeft(new Text("left")); |
root.setRight(new Text("right")); |
Pane shapesPane = new
Pane shapesPane = new Pane(); |
shapesPane.setPrefSize(300, 300); |
Line line = new
Line line = new Line(10, 10, 100, 100); // x1, y1, x2, | y2 y2
line.getStrokeDashArray().setAll(10.0d, 10.0d); // | dashes Rectangle rect = new dashes
Rectangle rect = new Rectangle(150, 10, 30, 40); // x, y, w, | h h
rect.setFill(Color.BLUE); |
Ellipse ell = new
Ellipse ell = new Ellipse(40, 180, 40, 30); // cx, cy, rx, | ry ry
ell.setStroke(Color.RED); |
ell.setFill(Color.GREEN); |
Text text = new
Text text = new Text(180, 180, "center"); |
List<String> fonts =
List<String> fonts = Font.getFamilies(); |
text.setFont(new Font(fonts.get((int) (Math.random() * fonts.size())), 32)); |
shapesPane.getChildren().addAll(line, rect, ell, text); |
root.setCenter(shapesPane); |
Scene scene = new
Scene scene = new Scene(root, 500, 500); |
stage.setTitle("BorderPaneApplication"); |
| ![](https://www.ntnu.no/wiki/download/attachments/65936865/BorderPaneShapesApplication.png?version=2&modificationDate=1394187023000&api=v2) |