RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 782886
Accepted
ProstoCoder
ProstoCoder
Asked:2020-02-10 03:25:05 +0000 UTC2020-02-10 03:25:05 +0000 UTC 2020-02-10 03:25:05 +0000 UTC

Control JavaFX 的响应式文本大小

  • 772

实际上,我已经为第 n 天的字体大小而苦恼了。情况如下:我在常规 AnchorPane 中添加了一个常规按钮,并将所有锚点设置为 30。现在,当我调整窗口大小时,按钮的大小会发生变化。但是字体大小没有变化!我已经尝试过以下选项。

  1. 我将侦听器附加到控件的大小,并根据高度和宽度值更改字体大小。但是这里的问题是,当你减小窗口的大小时,字体已经变成了一定的大小并且不允许 Control'y 减小,因此它本身就变得不可减少。
  2. 然后我尝试使用 JFXtras 中的 ScalableContentPane,但在 SceneBuilder 中无法制作 GUI 的事实存在差距,因为 为了使该对象正常工作,您需要向其 ContentPane 中添加子项,而不是向其添加子对象,该对象是在这样的代码中获得的new ScalableContentPane().getContentPane,并且它还奇怪地改变了它的大小,看起来马马虎虎......

这样的事情......我正在等待您的建议和解决方案,如果有不清楚的地方 - 写,我会澄清。这是代码以防万一...

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class FontSample extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
    AnchorPane anchorPane = new AnchorPane();
    anchorPane.setPrefSize(900, 700);

    Button button = new Button("MrButton");
    AnchorPane.setTopAnchor(button, 30.0);
    AnchorPane.setRightAnchor(button, 30.0);
    AnchorPane.setBottomAnchor(button, 30.0);
    AnchorPane.setLeftAnchor(button, 30.0);

    anchorPane.getChildren().add(button);

    primaryStage.setScene(new Scene(anchorPane));
    primaryStage.show();
}
}
java
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    ProstoCoder
    2020-02-10T06:11:19Z2020-02-10T06:11:19Z

    总的来说,我找到了绕过第1点问题的方法。这是代码

        import javafx.application.Application;
        import javafx.beans.property.DoubleProperty;
        import javafx.beans.property.SimpleDoubleProperty;
        import javafx.scene.Scene;
        import javafx.scene.control.Button;
        import javafx.scene.layout.AnchorPane;
        import javafx.scene.text.Font;
        import javafx.stage.Stage;
    
        public class FontSample extends Application {
        private DoubleProperty doubleProperty = new SimpleDoubleProperty(12);
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
            AnchorPane anchorPane = new AnchorPane();
            anchorPane.setPrefSize(900, 700);
    
            Button button = new Button("MrButton");
            AnchorPane.setTopAnchor(button, 30.0);
            AnchorPane.setRightAnchor(button, 30.0);
            AnchorPane.setBottomAnchor(button, 30.0);
            AnchorPane.setLeftAnchor(button, 30.0);
            anchorPane.getChildren().add(button);
    
            button.layoutBoundsProperty().addListener((observable, oldValue, newValue) -> {
            button.setFont(Font.font(Math.sqrt(newValue.getHeight() * 10)));
        });
    
    
            primaryStage.setScene(new Scene(anchorPane));
            primaryStage.show();
        }
    }
    

    在那里,当然,您可以自己选择计算字体大小的公式,但是这个公式很匆忙地出现在我面前,如果你再累一点,你几乎可以做任何你想做的事情......

    • 0

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5