Java Code Examples for javafx.scene.shape.Rectangle#setStyle()

The following examples show how to use javafx.scene.shape.Rectangle#setStyle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometryNodeOpacitySnippet.java    From gef with Eclipse Public License 2.0 8 votes vote down vote up
@Override
public Scene createScene() {
	Pane root = new Pane();
	Scene scene = new Scene(root, 300, 500);

	GeometryNode<RoundedRectangle> geometryNode = new GeometryNode<>(
			new RoundedRectangle(100, 100, 100, 100, 30, 30));
	geometryNode.setStroke(Color.TRANSPARENT);
	geometryNode.setStyle("-fx-fill: red; -fx-opacity: 0.5;");

	Rectangle rectangle = new Rectangle(100, 300, 100, 100);
	rectangle.setArcHeight(30);
	rectangle.setArcWidth(30);
	rectangle.setStroke(Color.TRANSPARENT);
	rectangle.setStyle("-fx-fill: red; -fx-opacity: 0.5;");

	root.getChildren().addAll(geometryNode, rectangle);

	return scene;
}
 
Example 2
Source File: ImageItem.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public Node makeNode(int size) {
    try {
        if (isColor()) {
            Rectangle rect = new Rectangle();
            rect.setFill(Color.web(address.substring(6)));
            rect.setWidth(size);
            rect.setHeight(size);
            rect.setStyle("-fx-padding: 10 10 10 10;-fx-background-radius: 10;");
            rect.setUserData(index);
            return rect;
        } else {
            if (image == null) {
                readImage();
            }
            ImageView view = new ImageView(image);
            view.setPreserveRatio(false);
            view.setFitWidth(size);
            view.setFitHeight(size);
            view.setUserData(index);
            return view;
        }
    } catch (Exception e) {
        return null;
    }
}
 
Example 3
Source File: SliderGlitchDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("nls")
@Override
public void start(final Stage stage)
{
    Slider slider = new Slider();
    slider.setOrientation(Orientation.VERTICAL);
    slider.setLayoutX(110);
    slider.setPrefHeight(200);
    slider.setValue(Double.NaN);

    Rectangle rect1 = createRect(10);
    rect1.setStyle("-fx-stroke-width: 1; -fx-stroke-dash-array: 5.0, 5.0; -fx-stroke: blue; -fx-fill: rgb(0, 0, 255, 0.05);");

    Rectangle rect2 = createRect(30);
    rect2.setStyle("-fx-stroke-width: 1; -fx-stroke: blue; -fx-fill: rgb(0, 0, 255, 0.05);");

    final Pane pane = new Pane(slider, rect1, rect2);
    pane.setPadding(new Insets(5));

    final Label label = new Label("Drag the bottom right corner of each rectangle across the slider. When the slider value is NaN,\n"
            + "the dashed rectangle freezes the program; the solid-bordered one disappears and reappears.\n"
            + "When it is finite, the rectangles behave as expected.");
    
    Button button = new Button("Toggle NaN/finite value.");
    button.setOnAction(e->
    {
        slider.setValue(Double.isFinite(slider.getValue()) ? Double.NaN : 50);
    });

    final VBox root = new VBox(pane, label, button);
    final Scene scene = new Scene(root, 800, 700);

    stage.setScene(scene);
    stage.setTitle("Slider Glitch Demo");

    stage.show();
}