【发布时间】:2015-08-26 01:38:32
【问题描述】:
我在调整 JavaFX 中 TextArea 的更新/事件的大小时遇到问题。为了说明,我通过 IntelliJ Idea 创建了空的 JavaFX 项目,其中 AnchorPane 作为根窗格,并且 AnchorPane 在 sample.fxml 文件中包含带有属性 AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" 的 TextArea(简而言之:TextArea 占用了场景的所有空间)。
问题描述:我启动应用程序并在一个小窗口 (300 x 275) 中启动。我只是最大化它。有正常的行为,但是当我回到窗口时,两个滚动条都显示了。当我将窗口大小调整为较小的窗口时,也会发生类似的情况。当我开始滚动时,TextArea 视口没有任何反应。当我开始写一些字母或将窗口调整为更大的窗口时,滚动条消失了。这是非常奇怪的行为!
我的问题:是否有任何侦听器或方法可以在不需要时捕获/停止显示滚动条?你也有这个问题吗?
从最大化状态返回后的屏幕截图
Main.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);
}
}
Controller.java
package sample;
public class Controller {
}
sample.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的错误,解决问题所在非常紧急!
【问题讨论】:
-
行为确实很奇怪。布局似乎也不重要,也可以使用
BorderLayout。也许你应该填写一份错误报告。 -
我在考虑。
-
我同意这可能是一个错误。如果将窗口拖得大一点,然后再小一点,滚动条就会出现和消失。我在表格中看到滚动条的类似行为 (javafx-jira.kenai.com/browse/RT-37359)。
-
这绝对是一个你应该报告的错误。我在我的应用程序中观察到同样的奇怪行为,但我自己还没有时间编写报告。
-
对不起,我忘记写评论了;我报告说...
标签: java javafx textarea scrollbar