Java Code Examples for javafx.scene.text.Text#setY()

The following examples show how to use javafx.scene.text.Text#setY() . 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: Hexagon.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public void renderCoordinates(GraphicsContext gc) {
    final Text text = new Text(position.getCoordinates());
    if (map != null) {
        // TODO re-enable font
        // text.setFont(map.getFont());
    }
    final double textWidth = text.getBoundsInLocal().getWidth();
    final double textHeight = text.getBoundsInLocal().getHeight();
    final double x = getGraphicsXoffset() - textWidth / 2;
    final double y = getGraphicsYoffset() + textHeight / 4;
    text.setX(x);
    text.setY(y);
    // Not sure why, but 4 seems like a good value
    gc.strokeText(position.getCoordinates(), x, y);
    // root.getChildren().add(text);
}
 
Example 2
Source File: RadarNodeChart.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void drawText() {
    final double CENTER_X      = 0.5 * width;
    final double CENTER_Y      = 0.5 * height;
    final int    NO_OF_SECTORS = getNoOfSectors();

    Font   font         = Fonts.latoRegular(0.035 * size);
    double radAngle     = RadarChartMode.SECTOR == getMode() ? Math.toRadians(180 + angleStep * 0.5) : Math.toRadians(180);
    double radAngleStep = Math.toRadians(angleStep);
    textGroup.getChildren().clear();
    for (int i = 0 ; i < NO_OF_SECTORS ; i++) {
        double r = size * 0.48;
        double x  = CENTER_X - size * 0.015 + (-Math.sin(radAngle) * r);
        double y  = CENTER_Y + (+Math.cos(radAngle) * r);

        Text text = new Text(data.get(i).getName());
        text.setFont(font);
        text.setFill(data.get(i).getTextColor());
        text.setTextOrigin(VPos.CENTER);
        text.setTextAlignment(TextAlignment.CENTER);
        text.setRotate(Math.toDegrees(radAngle) - 180);
        text.setX(x);
        text.setY(y);
        textGroup.getChildren().add(text);
        radAngle += radAngleStep;
    }
}
 
Example 3
Source File: FridayFunSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private Text createCenteredText(double cx, double cy, String styleClass) {
  Text text = new Text();
  text.getStyleClass().add(styleClass);
  text.setTextOrigin(VPos.CENTER);
  text.setTextAlignment(TextAlignment.CENTER);
  double width = cx > ARTBOARD_SIZE * 0.5 ? ((ARTBOARD_SIZE - cx) * 2.0) : cx * 2.0;
  text.setWrappingWidth(width);
  text.setBoundsType(TextBoundsType.VISUAL);
  text.setY(cy);
  text.setX(cx - (width / 2.0));

  return text;
}
 
Example 4
Source File: SlimSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private Text createCenteredText(double cx, double cy, String styleClass) {
  Text text = new Text();
  text.getStyleClass().add(styleClass);
  text.setTextOrigin(VPos.CENTER);
  text.setTextAlignment(TextAlignment.CENTER);
  double width = cx > ARTBOARD_WIDTH * 0.5 ? ((ARTBOARD_WIDTH - cx) * 2.0) : cx * 2.0;
  text.setWrappingWidth(width);
  text.setBoundsType(TextBoundsType.VISUAL);
  text.setY(cy);

  return text;
}
 
Example 5
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Text createTextHeader(String s) {
	Text t = new Text();
	t.setCache(true);
	t.setX(10.0f);
	t.setY(270.0f);
	t.setFill(Color.WHITE);//.LIGHTBLUE);// .ORANGE);//.DARKSLATEGREY);
	t.setText(s);
	t.setFont(Font.font(null, FontWeight.BOLD, 14));
	return t;
}
 
Example 6
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Text createBlackTextHeader(String s) {
	Text t = new Text();
	t.setCache(true);
	t.setX(10.0f);
	t.setY(270.0f);
	t.setFill(Color.BLACK);//.LIGHTBLUE);// .ORANGE);//.DARKSLATEGREY);
	t.setText(s);
	t.setFont(Font.font(null, FontWeight.BOLD, 14));
	return t;
}
 
Example 7
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image indicateSplitFx(Image image,
            List<Integer> rows, List<Integer> cols,
            Color lineColor, int lineWidth, boolean showSize) {
        try {
            if (rows == null || cols == null) {
                return image;
            }
            Group group = new Group();
            int width = (int) image.getWidth();
            int height = (int) image.getHeight();
            int row;
            for (int i = 0; i < rows.size(); ++i) {
                row = rows.get(i);
                if (row <= 0 || row >= height - 1) {
                    continue;
                }
                Line rowLine = new Line(0, row, width, row);
                rowLine.setStroke(lineColor);
                rowLine.setStrokeWidth(lineWidth);
                group.getChildren().add(rowLine);
            }
            int col;
            for (int i = 0; i < cols.size(); ++i) {
                col = cols.get(i);
                if (col <= 0 || col >= width - 1) {
                    continue;
                }
                Line colLine = new Line(col, 0, col, height);
                colLine.setStroke(lineColor);
                colLine.setStrokeWidth(lineWidth);
                group.getChildren().add(colLine);
            }

            if (showSize) {
                for (int i = 0; i < rows.size() - 1; ++i) {
                    int h = rows.get(i + 1) - rows.get(i) + 1;
                    for (int j = 0; j < cols.size() - 1; ++j) {
                        int w = cols.get(j + 1) - cols.get(j) + 1;
                        Text text = new Text();
                        text.setX(cols.get(j) + w / 3);
                        text.setY(rows.get(i) + h / 3);
                        text.setFill(lineColor);
                        text.setText(w + "x" + h);
                        text.setFont(new javafx.scene.text.Font(lineWidth * 3.0));
                        group.getChildren().add(text);
                    }
                }
            }

            Blend blend = new Blend(BlendMode.SRC_OVER);
            blend.setBottomInput(new ImageInput(image));
            group.setEffect(blend);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);

            return newImage;
        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }
    }
 
Example 8
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 4 votes vote down vote up
public void start2(Stage primaryStage) {
    try {
        BlendMode bm = BlendMode.MULTIPLY;
        //BlendMode bm = BlendMode.SRC_OVER;

        Text txt1 = new Text(bm.name());
        txt1.setX(100);
        txt1.setY(35);

        Text txt2 = new Text("Circle top");
        txt2.setX(70);
        txt2.setY(55);

        Text txt3 = new Text("Square top");
        txt3.setX(160);
        txt3.setY(55);

        Text txt4 = new Text("Circle opacity - 0.5\nSquare opacity - 1.0");
        txt4.setX(70);
        txt4.setY(185);

        Circle c1 = createCircle(80, 95);
        Rectangle s1 = createSquare(80, 95);

        Circle c2 = createCircle(180, 95);
        Rectangle s2 = createSquare(180, 95);

        Pane pane = new Pane();
        pane.setPadding(new Insets(20, 20, 20, 20));
        pane.getChildren().addAll(txt1,txt2,txt3,s1,c1,c2,s2,txt4);
        pane.setBlendMode(bm);

        Scene scene = new Scene(pane, 300, 250);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX blend effect");
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();
    } catch (Exception ex){
        ex.printStackTrace();
    }
}