我在调整 JavaFX 中 TextArea 的更新/事件大小时遇到问题。为了便于说明,我通过 IntelliJ Idea 创建了空的 JavaFX 项目,其中 AnchorPane 作为根窗格,并且 AnchorPane 包含带有属性的 TextAreaAnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
在sample.fxml 文件中(简而言之:TextArea 占据场景的所有空间)。
问题描述:我启动应用程序,它在一个小窗口 (300 x 275) 中启动。我只是将其最大化。这是正常的行为,但是当我回到窗口时,两个滚动条都显示了。当我将窗口大小调整为更小的窗口时,会发生类似的情况。当我开始滚动时,TextArea 视口没有任何反应。当我开始写一些字母或将窗口大小调整为更大的窗口时,滚动条消失了。这是非常奇怪的行为!
我的问题:是否有任何侦听器或方法可以在不需要时捕获/停止显示滚动条?你也有这个问题吗?
从最大化形式返回后的屏幕截图
主程序.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
控制器.java
package sample;
public class Controller {
}
样本.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TextArea layoutX="162.0" layoutY="66.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
PS:抱歉我的英语和重复插入该问题,但是如果是JavaFX的bug,那么解决问题出在哪里是非常急迫的!