javafx.scene.text.Text.setFont()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中javafx.scene.text.Text.setFont()方法的一些代码示例,展示了Text.setFont()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text.setFont()方法的具体详情如下:
包路径:javafx.scene.text.Text
类名称:Text
方法名:setFont

Text.setFont介绍

暂无

代码示例

代码示例来源:origin: jfoenixadmin/JFoenix

private double computeTextContentWidth(TextInputControl editor) {
  Text text = new Text(editor.getText());
  text.setFont(editor.getFont());
  text.applyCss();
  return text.getLayoutBounds().getWidth();
}

代码示例来源:origin: jfoenixadmin/JFoenix

temp.setFont(text.getFont());
temp.applyCss();
double width = temp.getLayoutBounds().getWidth();

代码示例来源:origin: jfoenixadmin/JFoenix

/**
 * {@inheritDoc}
 */
@Override
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) {
  final double strokeWidth = arc.getStrokeWidth();
  final double radius = Math.min(contentWidth, contentHeight) / 2 - strokeWidth / 2;
  final double arcSize = snapSize(radius * 2 + strokeWidth);
  arcPane.resizeRelocate((contentWidth - arcSize) / 2 + 1, (contentHeight - arcSize) / 2 + 1, arcSize, arcSize);
  updateArcLayout(radius, arcSize);
  fillRect.setWidth(arcSize);
  fillRect.setHeight(arcSize);
  if (!isValid) {
    initialize();
    isValid = true;
  }
  if (!getSkinnable().isIndeterminate()) {
    arc.setLength(arcLength);
    if (text.isVisible()) {
      final double progress = control.getProgress();
      int intProgress = (int) Math.round(progress * 100.0);
      Font font = text.getFont();
      text.setFont(Font.font(font.getFamily(), radius / 1.7));
      text.setText((progress > 1 ? 100 : intProgress) + "%");
      text.relocate((arcSize - text.getLayoutBounds().getWidth()) / 2, (arcSize - text.getLayoutBounds().getHeight()) / 2);
    }
  }
}

代码示例来源:origin: ch.sahits.game/OpenPatricianDisplay

public void setFont(Font f) {
  cashTxt.setFont(f);
  dateTxt.setFont(f);
}

代码示例来源:origin: ch.sahits.game/OpenPatricianDisplay

public void setFont(Font f) {
  cityName.setFont(f);
}

代码示例来源:origin: org.controlsfx/controlsfx

private void refreshSample() {
  sample.setFont(getFont());
}

代码示例来源:origin: com.guigarage/ui-basics

public static Text createIconText(Character c, double fontSize) {
  Text iconT = new Text(c + "");
  iconT.setFont(Font.loadFont(UiUtilities.class.getResourceAsStream("fontawesome-webfont.ttf"), fontSize));
  return iconT;
}

代码示例来源:origin: org.processing/core

@Override
protected float textWidthImpl(char[] buffer, int start, int stop) {
 if (textFont == null) {
  defaultFontOrDeath("textWidth");
 }
 if (textFontInfo.font == null) {
  return super.textWidthImpl(buffer, start, stop);
 }
 fontCache.measuringText.setFont(textFontInfo.font);
 fontCache.measuringText.setText(new String(buffer, start, stop - start));
 return (float) fontCache.measuringText.getLayoutBounds().getWidth();
}

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

void updateIcon(FontIcon icon, double size) {
    this.text.setFont(Font.font(icon.getFont().getFamily(), size));
    this.text.setText(Character.toString(icon.getIconCode()));
  }
}

代码示例来源:origin: org.fuin.devsupwiz/devsupwiz-common

private void writeLine() {
  final Text text = new Text(line.toString());
  text.setFill(color);
  text.setFont(Font.font("MONOSPACED"));
  if (Platform.isFxApplicationThread()) {
    textFlow.getChildren().add(text);
  } else {
    Platform.runLater(new Runnable() {
      @Override
      public void run() {
        textFlow.getChildren().add(text);
      }
    });
  }
  line = new StringBuilder();
}

代码示例来源:origin: ch.sahits.game/OpenPatricianJavaFX

double computeTextWidth(Font font, String text, double wrappingWidth) {
  Text helper = new Text();
  helper.setFont(font);
  helper.setText(text);
  // Note that the wrapping width needs to be set to zero before
  // getting the text's real preferred width.
  helper.setWrappingWidth(0);
  helper.setLineSpacing(0);
  double w = Math.min(helper.prefWidth(-1), wrappingWidth);
  helper.setWrappingWidth((int)Math.ceil(w));
  return Math.ceil(helper.getLayoutBounds().getWidth());
}

代码示例来源:origin: com.github.almasb/fxgl-base

private void initProfilerText(double x, double y) {
  profilerText.setFont(FXGL.getUIFactory().newFont(FontType.MONO, 20.0));
  profilerText.setFill(Color.RED);
  profilerText.setTranslateX(x);
  profilerText.setTranslateY(y);
  uiRoot.getChildren().add(profilerText);
}

代码示例来源:origin: com.gitlab.cdc-java.ui/cdc-ui-fx

public static Text toBoldText(String text) {
  final Text w = new Text(text);
  final Font font = w.getFont();
  w.setFont(Font.font(font.getName(), FontWeight.BOLD, font.getSize()));
  return w;
}

代码示例来源:origin: org.processing/core

FontInfo createFontInfo(Font font) {
 FontInfo result = new FontInfo();
 result.font = font;
 if (font != null) {
  // measure ascent and descent
  measuringText.setFont(result.font);
  measuringText.setText(" ");
  float lineHeight = (float) measuringText.getLayoutBounds().getHeight();
  result.ascent = (float) measuringText.getBaselineOffset();
  result.descent = lineHeight - result.ascent;
 }
 return result;
}

代码示例来源:origin: ch.sahits.game/OpenPatricianJavaFX

double computeTextHeight(Font font, String text, double wrappingWidth, double lineSpacing) {
  Text helper = new Text();
  helper.setFont(font);
  helper.setText(text);
  helper.setWrappingWidth((int)wrappingWidth);
  helper.setLineSpacing(lineSpacing);
  return helper.getLayoutBounds().getHeight();
}
/**

代码示例来源:origin: com.jfoenix/jfoenix

private double computeTextContentWidth(TextInputControl editor) {
  Text text = new Text(editor.getText());
  text.setFont(editor.getFont());
  text.applyCss();
  return text.getLayoutBounds().getWidth();
}

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

public static double getTextHeight(String text, Font font, double fontZoomFactor) {
  Text t = new Text(text);
  t.setFont(Font.font(font.getName(), font.getSize() * fontZoomFactor));
  return t.getLayoutBounds().getHeight();
}

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

/**
 * Calculate the size of the text with the given font
 *
 * @param text
 *            the text
 * @param font
 *            the font
 * @return the width
 * @since 2.3.0
 */
public static double getTextWidth(String text, Font font, double fontZoomFactor) {
  Text t = new Text(text);
  t.setFont(Font.font(font.getName(), font.getSize() * fontZoomFactor));
  return t.getLayoutBounds().getWidth();
}

代码示例来源:origin: com.github.vatbub/common.view.core

static int computeTruncationIndex(Font font, String text, double width) {
    helper.setText(text);
    helper.setFont(font);
    helper.setWrappingWidth(0);
    helper.setLineSpacing(0);
    // The -2 is a fudge to make sure the result more often matches
    // what we get from using computeTextWidth instead. It's not yet
    // clear what causes the small discrepancies.
    Bounds bounds = helper.getLayoutBounds();
    Point2D endPoint = new Point2D(width - 2, bounds.getMinY() + bounds.getHeight() / 2);
    //noinspection deprecation
    final int index = helper.impl_hitTestChar(endPoint).getCharIndex();
    // RESTORE STATE
    helper.setWrappingWidth(DEFAULT_WRAPPING_WIDTH);
    helper.setLineSpacing(DEFAULT_LINE_SPACING);
    helper.setText(DEFAULT_TEXT);
    return index;
  }
}

代码示例来源:origin: PhoenicisOrg/phoenicis

protected void drawLeftImage() {
  AnchorPane pane = new AnchorPane();
  pane.setPrefWidth(187);
  Stop[] stops = new Stop[] { new Stop(0, Color.web("#3c79b2")), new Stop(1, Color.web("#2d5d8b")) };
  RadialGradient gradient = new RadialGradient(0, 0, 0.5, 0.5, 1, true, CycleMethod.NO_CYCLE, stops);
  Background background = new Background(new BackgroundFill(gradient, null, null));
  pane.setBackground(background);
  Text text = new Text(this.parent.getLeftImageText());
  text.setFill(Color.WHITE);
  text.setFont(Font.font("Maven Pro", 50));
  text.setRotate(-90);
  pane.setPadding(new Insets(-50));
  pane.getChildren().add(text);
  AnchorPane.setBottomAnchor(text, 160.0);
  AnchorPane.setRightAnchor(text, -40.0);
  getParent().getRoot().setLeft(pane);
}

相关文章