Skip to content

Commit fa76ed0

Browse files
committed
Exemplify setting an image as a vertex's background #34.
1 parent 4db0d62 commit fa76ed0

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

squares.jpg

136 KB
Loading

src/main/java/com/brunomnsilva/smartgraph/example/ExampleMain.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy;
3232
import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
3333
import com.brunomnsilva.smartgraph.graphview.SmartGraphProperties;
34-
import com.brunomnsilva.smartgraph.graphview.SmartGraphVertex;
3534
import javafx.application.Application;
3635
import javafx.scene.Scene;
3736
import javafx.stage.Stage;
@@ -95,11 +94,20 @@ public void start(Stage ignored) {
9594
graphView.setVertexPosition(prague, 824, 668);
9695
graphView.setVertexPosition(tokyo, 512, 200);
9796
graphView.setVertexPosition(newYork, 512, 400);
98-
99-
graphView.getStylableLabel(tokyo).setStyleInline("-fx-stroke: green; -fx-fill: green;");
10097

101-
graphView.setVertexDoubleClickAction((SmartGraphVertex<City> graphVertex) -> {
102-
graphVertex.addStyleClass("myVertex");
98+
/*
99+
* This illustrates setting an image to the background of a node.
100+
* By default, the css class "vertex" is applied to all vertices.
101+
* Note that all inline styles have
102+
* priority over any properties set in css classes, even if they are applied cumulatively through
103+
* .addStyleClass(class). However, inline styles can be overwritten by using .setStyleInline(css);
104+
* also, when you use .setStyleClass(class), all previous styles will be discarded, including inline.
105+
*/
106+
graphView.getStylableVertex(tokyo).setStyleInline("-fx-fill: url(\"file:squares.jpg\");");
107+
//graphVertex.setStyleInline("-fx-fill: red;"); //this will overwrite the property later on
108+
109+
graphView.setVertexDoubleClickAction(graphVertex -> {
110+
graphVertex.setStyleClass("myVertex");
103111
});
104112

105113
}

0 commit comments

Comments
 (0)