Luis Averhoff
Luis Averhoff

Reputation: 395

Trying to draw a line with SVGPath in FXML

So I'm trying to learn how to use svg in FXML and the first thing I want to do is to draw a simple line and then work my way up to other shapes. From what I've gathered online, all I have to do is give it a moveTo point and then a line point. If that's the case, then what am I missing?

<Button prefHeight="30" prefWidth="200" >
    <shape>
        <javafx.scene.shape.SVGPath content="M100,100 L150,150" /> 
    </shape>
</Button>

Upvotes: 1

Views: 2337

Answers (1)

jewelsea
jewelsea

Reputation: 159290

Sample Solution

svg path

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.paint.*?>
<?import javafx.scene.layout.*?>
<?import java.lang.*?>
<?import javafx.scene.shape.*?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="86.0" prefWidth="99.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <SVGPath content="M40,60 L20,20" layoutX="18.0" layoutY="2.0" stroke="BLACK" strokeWidth="3.0" />
   </children>
</Pane>

Background

You can refer to this tutorial on svg paths for background information (note JavaFX only processes path strings not full svg XML documents).

Upvotes: 1

Related Questions