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

The following examples show how to use javafx.scene.shape.Rectangle#setStrokeWidth() . 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: StrokeTransitionSample.java    From marathonv5 with Apache License 2.0 8 votes vote down vote up
public StrokeTransitionSample() {
    super(150,150);
    Rectangle rect = new Rectangle(0, 0, 150, 150);
    rect.setArcHeight(20);
    rect.setArcWidth(20);
    rect.setFill(null);
    rect.setStroke(Color.DODGERBLUE);
    rect.setStrokeWidth(10);
    getChildren().add(rect);
    
    strokeTransition = StrokeTransitionBuilder.create()
        .duration(Duration.seconds(3))
        .shape(rect)
        .fromValue(Color.RED)
        .toValue(Color.DODGERBLUE)
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();
}
 
Example 2
Source File: KeyboardExample.java    From JavaFX with MIT License 6 votes vote down vote up
public Node createNode() {
	final StackPane keyNode = new StackPane();
	keyNode.setFocusTraversable(true);
	installEventHandler(keyNode);

	final Rectangle keyBackground = new Rectangle(50, 50);
	keyBackground.fillProperty().bind(
			Bindings.when(pressedProperty)
					.then(Color.RED)
					.otherwise(
							Bindings.when(keyNode.focusedProperty())
									.then(Color.LIGHTGRAY)
									.otherwise(Color.WHITE)));
	keyBackground.setStroke(Color.BLACK);
	keyBackground.setStrokeWidth(2);
	keyBackground.setArcWidth(12);
	keyBackground.setArcHeight(12);

	final Text keyLabel = new Text(keyCode.getName());
	keyLabel.setFont(Font.font("Arial", FontWeight.BOLD, 20));

	keyNode.getChildren().addAll(keyBackground, keyLabel);

	return keyNode;
}
 
Example 3
Source File: SpaceInvadersFactory.java    From FXGLGames with MIT License 6 votes vote down vote up
@Spawns("LaserBeam")
public Entity newLaserBeam(SpawnData data) {
    Rectangle view = new Rectangle(10, Config.HEIGHT - 25, Color.color(1.0, 1.0, 1.0, 0.86));
    view.setArcWidth(15);
    view.setArcHeight(15);
    view.setStroke(Color.BLUE);
    view.setStrokeWidth(1);

    return entityBuilder()
            .from(data)
            .type(LASER_BEAM)
            .viewWithBBox(view)
            .with(new CollidableComponent(true))
            .with(new LaserBeamComponent())
            .build();
}
 
Example 4
Source File: JFXChartUtil.java    From jfxutils with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method for simple and default setup of zooming on an {@link XYChart} via a
 * {@link ChartZoomManager}. Wraps the chart in the components required to implement zooming. The
 * current implementation wraps the chart in a StackPane, which has the chart and a blue
 * translucent rectangle as children. Returns the top level of the created components.
 * <p>
 * If the chart already has a parent, that parent must be a {@link Pane}, and the chart is
 * replaced with the wrapping region, and the return value could be ignored. If the chart does
 * not have a parent, the same wrapping node is returned, which will need to be added to some
 * parent.
 * <p>
 * The chart's axes must both be a type of ValueAxis.
 * <p>
 * The wrapping logic does not seem to be perfect, in fact there is a special case to handle
 * {@link BorderPane}s. If it's not found to be reliable, then create the wrapping components
 * yourself (such as in the FXML), or setup zooming before adding it to a parent.
 *
 * @param mouseFilter EventHandler that consumes events that should not trigger a zoom action
 *
 * @return The top-level Region
 */
public static Region setupZooming( XYChart<?, ?> chart,
                                   EventHandler<? super MouseEvent> mouseFilter ) {
	StackPane chartPane = new StackPane();

	if ( chart.getParent() != null )
		JFXUtil.replaceComponent( chart, chartPane );

	Rectangle selectRect = new Rectangle( 0, 0, 0, 0 );
	selectRect.setFill( Color.DODGERBLUE );
	selectRect.setMouseTransparent( true );
	selectRect.setOpacity( 0.3 );
	selectRect.setStroke( Color.rgb( 0, 0x29, 0x66 ) );
	selectRect.setStrokeType( StrokeType.INSIDE );
	selectRect.setStrokeWidth( 3.0 );
	StackPane.setAlignment( selectRect, Pos.TOP_LEFT );

	chartPane.getChildren().addAll( chart, selectRect );

	ChartZoomManager zoomManager = new ChartZoomManager( chartPane, selectRect, chart );
	zoomManager.setMouseFilter( mouseFilter );
	zoomManager.start();
	return chartPane;
}
 
Example 5
Source File: ColorPalettePreviewField.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private void setRectangles() {
  rects.clear();

  if (palette == null || palette.isEmpty()) {
    return;
  }

  for (int i = 0; i < palette.size(); i++) {
    Color clr = palette.get(i);
    Rectangle rect = new DraggableRectangle(RECT_HEIGHT - STROKE_WIDTH / 2,
        RECT_HEIGHT - STROKE_WIDTH / 2);

    rects.add(rect);

    rect.setFill(clr);
    rect.setStroke(STROKE_CLR_DEFAULT);
    rect.setStrokeWidth(STROKE_WIDTH);

    rect.setOnMousePressed(e -> {
      setSelected(rect);
    });
  }
}
 
Example 6
Source File: DesktopApp.java    From FXTutorials with MIT License 5 votes vote down vote up
DesktopIcon(String name, Class<? extends Application> appClass) {
    this.name = name;
    this.appClass = appClass;

    Rectangle bg = new Rectangle(100, 100, null);
    bg.setStroke(Color.BLACK);
    bg.setStrokeWidth(2.5);

    Text text = new Text(name);

    getChildren().addAll(bg, text);
}
 
Example 7
Source File: PageView.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a view of a page.
 * @param origin The origin point where the page has to be placed. Cannot be null.
 */
public PageView(final @NotNull PreferencesService prefs, final Point origin) {
	super();

	recPage = new Rectangle();
	recShadowBottom = new Rectangle();
	recShadowRight = new Rectangle();

	recPage.setStrokeWidth(1d);
	recPage.setStroke(Color.BLACK);
	recPage.setFill(null);
	recPage.setX(origin.getX());
	recPage.setY(origin.getY());

	recShadowRight.setStroke(null);
	recShadowBottom.setStroke(null);
	recShadowRight.setFill(Color.GRAY);
	recShadowBottom.setFill(Color.GRAY);

	getChildren().add(recShadowBottom);
	getChildren().add(recShadowRight);
	getChildren().add(recPage);

	recPage.toFront();
	setMouseTransparent(true);
	setFocusTraversable(false);

	update(prefs.getPage());
	prefs.pageProperty().addListener((observable, oldValue, newValue) -> update(newValue));
}
 
Example 8
Source File: OverviewPanel.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that creates and styles a POV object.
 *
 * The POV object is a styled rectangle that is used to indicate the
 * currently observed time range (aka time extent) on the timeline. It can
 * also be used to quickly interact with the time extent.
 *
 * @return A formatted POV object.
 */
private Rectangle createPOV() {
    final Rectangle rect = new Rectangle(135, 25, 60, 1);

    // Bind the height of the POV to the Height of the histogram:
    rect.yProperty().bind(histogram.heightProperty());
    rect.heightProperty().bind(innerPane.prefHeightProperty());
    rect.setManaged(true);

    // Style the rectangle:
    rect.setStroke(Color.DODGERBLUE);
    rect.setStrokeWidth(2d);
    final LinearGradient gradient
            = new LinearGradient(0.0, 0.0, 0.0, 0.5, true, CycleMethod.NO_CYCLE, new Stop[]{
        new Stop(0, Color.LIGHTBLUE.darker()),
        new Stop(1, Color.TRANSPARENT)
    });
    rect.setFill(gradient);
    rect.setSmooth(true);

    // Round the edges of the rectangle:
    rect.setArcWidth(5.0);
    rect.setArcHeight(5.0);

    // Set the POV mouse event handlers:
    final POVMouseEventHandler handler = new POVMouseEventHandler(rect);
    rect.setOnMouseMoved(handler);
    rect.setOnMousePressed(handler);
    rect.setOnMouseDragged(handler);
    rect.setOnMouseReleased(handler);

    // Make the POV object the top-most object on this panel:
    rect.toFront();

    return rect;
}
 
Example 9
Source File: RectangleSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    Rectangle rectangle = new Rectangle(40,40);
    rectangle.setStroke(Color.web("#b9c0c5"));
    rectangle.setStrokeWidth(5);
    rectangle.getStrokeDashArray().addAll(15d,15d);
    rectangle.setFill(null);
    javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
    effect.setOffsetX(1);
    effect.setOffsetY(1);
    effect.setRadius(3);
    effect.setColor(Color.rgb(0,0,0,0.6));
    rectangle.setEffect(effect);
    return rectangle;
}
 
Example 10
Source File: ColorPaletteCell.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
protected Rectangle makeRect(@Nonnull Color clr) {
  Rectangle rect = new Rectangle(height - STROKE_WIDTH * 2, height - STROKE_WIDTH * 2);
  rect.setFill(clr);
  rect.setStroke(STROKE_CLR);
  rect.setStrokeWidth(STROKE_WIDTH);
  return rect;
}
 
Example 11
Source File: StopWatch.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Rectangle createBackground(Color stroke, Color fill) {
    Rectangle background = new Rectangle(14, 17, fill);
    background.setStroke(stroke);
    background.setStrokeWidth(2);
    background.setEffect(new Lighting());
    background.setCache(true);
    return background;
}
 
Example 12
Source File: SpaceLevel.java    From FXGLGames with MIT License 5 votes vote down vote up
public SpaceLevel() {
    Rectangle bg = new Rectangle(getAppWidth() - 20, 200, Color.color(0, 0, 0, 0.6));
    bg.setArcWidth(25);
    bg.setArcHeight(25);
    bg.setStroke(Color.color(0.1, 0.2, 0.86, 0.76));
    bg.setStrokeWidth(3);

    storyPane.setTranslateX(10);
    storyPane.setTranslateY(25);

    rootPane = new Pane(bg, storyPane);
    rootPane.setTranslateX(10);
    rootPane.setTranslateY(getAppHeight() - 200);
}
 
Example 13
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ScaleSample() {
    super(180,180);
    // simple rectangle
    Rectangle rect1 = new Rectangle(0, 25, 25, 25);
    rect1.setArcHeight(15);
    rect1.setArcWidth(15);
    rect1.setFill(Color.WHITE);
    rect1.setStroke(Color.DODGERBLUE);
    rect1.setStrokeWidth(3);
    
    Polygon arrow = createArrow();
    arrow.setLayoutX(46);
    arrow.setLayoutY(22);
    arrow.setRotate(90);
    
    // simple rectangle with scale 2 in X axis and 0.5 in Y
    Rectangle rect2 = new Rectangle(95, 25, 25, 25);
    rect2.setArcHeight(15);
    rect2.setArcWidth(15);
    rect2.setFill(Color.WHITE);
    rect2.setStroke(Color.DODGERBLUE);
    rect2.setStrokeWidth(3);
    rect2.setScaleX(2);
    rect2.setScaleY(0.5);
    // rectangle with adjustable scale
    Rectangle rect3 = new Rectangle(40, 130, 25, 25);
    rect3.setArcHeight(15);
    rect3.setArcWidth(15);
    rect3.setFill(Color.WHITE);
    rect3.setStroke(Color.DODGERBLUE);
    rect3.setStrokeWidth(3);
    rect3.setScaleX(6);
    rect3.setScaleY(0.5);
    rect3.setTranslateX(rect3.getTranslateX()+30);
    //getChildren().addAll(rect1, rect2, rect3);
    getChildren().addAll(rect1, arrow, rect2, rect3);
    
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Scale X", rect3.scaleXProperty(), 0.1d, 16d),
            new SimplePropertySheet.PropDesc("Scale Y", rect3.scaleYProperty(), 0.1d, 4d)
    );
    // END REMOVE ME
}
 
Example 14
Source File: StopWatchSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private Rectangle createDotBackground() {
    Rectangle background = new Rectangle(8, 17, Color.TRANSPARENT);
    background.setStroke(Color.TRANSPARENT);
    background.setStrokeWidth(2);
    return background;
}
 
Example 15
Source File: Exercise_16_03.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application calss
public void start(Stage primaryStage) {
	// Create a vbox
	VBox paneForCircles = new VBox(5);
	paneForCircles.setAlignment(Pos.CENTER);

	// Create three circles
	Circle c1 = getCircle();
	Circle c2 = getCircle();
	Circle c3 = getCircle();
	c1.setFill(Color.RED);

	// Place circles in vbox
	paneForCircles.getChildren().addAll(c1, c2, c3);

	// Create a rectangle
	Rectangle rectangle = new Rectangle();
	rectangle.setFill(Color.WHITE);
	rectangle.setWidth(30);
	rectangle.setHeight(100);
	rectangle.setStroke(Color.BLACK);
	rectangle.setStrokeWidth(2);
	StackPane stopSign = new StackPane(rectangle, paneForCircles);

	// Create a hbox
	HBox paneForRadioButtons = new HBox(5);
	paneForRadioButtons.setAlignment(Pos.CENTER);

	// Create radio buttons
	RadioButton rbRed = new RadioButton("Red");
	RadioButton rbYellow = new RadioButton("Yellow");
	RadioButton rbGreen = new RadioButton("Green");

	// Create a toggle group
	ToggleGroup group = new ToggleGroup();
	rbRed.setToggleGroup(group);
	rbYellow.setToggleGroup(group);
	rbGreen.setToggleGroup(group);
	rbRed.setSelected(true);
	paneForRadioButtons.getChildren().addAll(rbRed, rbYellow, rbGreen);

	// Create a border pane
	BorderPane pane = new BorderPane();
	pane.setCenter(stopSign);
	pane.setBottom(paneForRadioButtons);

	// Create and register handlers
	rbRed.setOnAction(e -> {
		if (rbRed.isSelected()) {
			c1.setFill(Color.RED);
			c2.setFill(Color.WHITE);
			c3.setFill(Color.WHITE);
		}
	});

	rbYellow.setOnAction(e -> {
		if (rbYellow.isSelected()) {
			c1.setFill(Color.WHITE);
			c2.setFill(Color.YELLOW);
			c3.setFill(Color.WHITE);
		}
	});

	rbGreen.setOnAction(e -> {
		if (rbGreen.isSelected()) {
			c1.setFill(Color.WHITE);
			c2.setFill(Color.WHITE);
			c3.setFill(Color.GREEN);
		}
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 200, 150);
	primaryStage.setTitle("Exercise_16_03"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 16
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ScaleSample() {
    super(180,180);
    // simple rectangle
    Rectangle rect1 = new Rectangle(0, 25, 25, 25);
    rect1.setArcHeight(15);
    rect1.setArcWidth(15);
    rect1.setFill(Color.WHITE);
    rect1.setStroke(Color.DODGERBLUE);
    rect1.setStrokeWidth(3);
    
    Polygon arrow = createArrow();
    arrow.setLayoutX(46);
    arrow.setLayoutY(22);
    arrow.setRotate(90);
    
    // simple rectangle with scale 2 in X axis and 0.5 in Y
    Rectangle rect2 = new Rectangle(95, 25, 25, 25);
    rect2.setArcHeight(15);
    rect2.setArcWidth(15);
    rect2.setFill(Color.WHITE);
    rect2.setStroke(Color.DODGERBLUE);
    rect2.setStrokeWidth(3);
    rect2.setScaleX(2);
    rect2.setScaleY(0.5);
    // rectangle with adjustable scale
    Rectangle rect3 = new Rectangle(40, 130, 25, 25);
    rect3.setArcHeight(15);
    rect3.setArcWidth(15);
    rect3.setFill(Color.WHITE);
    rect3.setStroke(Color.DODGERBLUE);
    rect3.setStrokeWidth(3);
    rect3.setScaleX(6);
    rect3.setScaleY(0.5);
    rect3.setTranslateX(rect3.getTranslateX()+30);
    //getChildren().addAll(rect1, rect2, rect3);
    getChildren().addAll(rect1, arrow, rect2, rect3);
    
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Scale X", rect3.scaleXProperty(), 0.1d, 16d),
            new SimplePropertySheet.PropDesc("Scale Y", rect3.scaleYProperty(), 0.1d, 4d)
    );
    // END REMOVE ME
}
 
Example 17
Source File: StopWatchSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private Rectangle createDotBackground() {
    Rectangle background = new Rectangle(8, 17, Color.TRANSPARENT);
    background.setStroke(Color.TRANSPARENT);
    background.setStrokeWidth(2);
    return background;
}
 
Example 18
Source File: ToggleButtonSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);
    stage.setHeight(180);

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    Scene scene = new Scene(new Group(vbox));
    stage.setScene(scene);
    scene.getStylesheets().add("togglebuttonsample/ControlStyle.css");

    Rectangle rect = new Rectangle();
    rect.setHeight(50);
    rect.setFill(Color.WHITE);
    rect.setStroke(Color.DARKGRAY);
    rect.setStrokeWidth(2);
    rect.setArcHeight(10);
    rect.setArcWidth(10);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) -> {
        if (new_toggle == null)
            rect.setFill(Color.WHITE);
        else
            rect.setFill((Color) group.getSelectedToggle().getUserData());
    });

    ToggleButton tb1 = new ToggleButton("Minor");
    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);
    tb1.getStyleClass().add("toggle-button1");

    ToggleButton tb2 = new ToggleButton("Major");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    tb2.getStyleClass().add("toggle-button2");

    ToggleButton tb3 = new ToggleButton("Critical");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);
    tb3.getStyleClass().add("toggle-button3");

    hbox.getChildren().addAll(tb1, tb2, tb3);

    vbox.getChildren().add(new Label("Priority:"));
    vbox.getChildren().add(hbox);
    vbox.getChildren().add(rect);
    vbox.setPadding(new Insets(20, 10, 10, 20));

    stage.show();
    rect.setWidth(hbox.getWidth());
}
 
Example 19
Source File: StopWatch.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Rectangle createDotBackground() {
    Rectangle background = new Rectangle(8, 17, Color.TRANSPARENT);
    background.setStroke(Color.TRANSPARENT);
    background.setStrokeWidth(2);
    return background;
}
 
Example 20
Source File: TextFlowApp.java    From oim-fx with MIT License 2 votes vote down vote up
public Parent createContent() {

		String family = "Helvetica";

		double size = 20;

		// Simple example

		textFlow = new TextFlow();
		
		textHello = new Text("Hello ");

		textHello.setFont(Font.font(family, size));
		textBold = new Text("Bold");
		textBold.setFont(Font.font(family, FontWeight.BOLD, size));
		textWorld = new Text(" World");
		textWorld.setFont(Font.font(family, FontPosture.ITALIC, size));
		textFlow.getChildren().addAll(textHello, textBold, textWorld);

		// Example with embedded objects

		TextFlow textFlowEmbedObj = new TextFlow();
		Text textEO1 = new Text("Lets have ");
		textEO1.setFont(Font.font(family, size));
		Text textEO2 = new Text("embedded objects: a Rectangle ");

		textEO2.setFont(Font.font(family, FontWeight.BOLD, size));

		Rectangle rect = new Rectangle(80, 60);

		rect.setFill(null);
		rect.setStroke(Color.GREEN);
		rect.setStrokeWidth(5);
		Text textEO3 = new Text(", then a button ");

		Button button = new Button("click me");
		Text textEO4 = new Text(", and finally an image ");

		ImageView imageView = new ImageView(image);
		Text textEO5 = new Text(".");

		textEO5.setFont(Font.font(family, size));

		textFlowEmbedObj.getChildren().addAll(textEO1, textEO2, rect, textEO3, button, textEO4, imageView, textEO5);

		VBox vbox = new VBox(18);

		VBox.setMargin(textFlow, new Insets(5, 5, 0, 5));

		VBox.setMargin(textFlowEmbedObj, new Insets(0, 5, 5, 5));

		vbox.getChildren().addAll(textFlow, textFlowEmbedObj);
		return vbox;

	}