TextFlow与TextArea,布局问题; 为什么TextFlow会把它弄乱到TextArea没有的地方?

fge*_*fge 4 java layout javafx fxml javafx-8

这是原始的fxml文件(为简洁起见省略了导入):

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
    minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0"
    xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
    fx:id="pane"
    fx:controller="com.github.parboiled1.grappa.debugger.mainwindow.MainWindowUi">
    <top>
        <MenuBar BorderPane.alignment="CENTER">
            <Menu mnemonicParsing="false" text="File">
                <!-- INJECTION -->
                <MenuItem fx:id="loadInput" mnemonicParsing="false"
                    text="Load file" onAction="#loadFileEvent"/>
                <MenuItem fx:id="parse" mnemonicParsing="false"
                    text="Parse" onAction="#parseEvent"/>
                <MenuItem fx:id="closeButton" mnemonicParsing="false"
                    text="Close" onAction="#closeWindowEvent"/>
            </Menu>
        </MenuBar>
    </top>
    <center>
        <SplitPane dividerPositions="0.5" prefHeight="160.0" prefWidth="200.0"
            BorderPane.alignment="CENTER">
            <SplitPane dividerPositions="0.5" orientation="VERTICAL">
                <TreeView fx:id="traceTree" prefHeight="200.0"
                    prefWidth="200.0" style="font-family: monospace"/>
                <TextArea fx:id="traceDetail" editable="false"
                    prefHeight="200.0" prefWidth="200.0"
                    style="-fx-font-family: monospace"/>
            </SplitPane>
            <!-- HERE -->
            <TextArea fx:id="inputText" prefHeight="200.0" prefWidth="200.0"/>
        </SplitPane>
    </center>
</BorderPane>
Run Code Online (Sandbox Code Playgroud)

我想执行的文本高亮部分在什么是现在的文本TextAreafx:idinputText.为此,我建议使用a TextFlow而不是a TextArea."XML评论":HERE.

在"XML注释"中INJECTION,我已经有了inputText用(文本)文件的内容填充内容的方法.这适用于TextArea.

现在,我做了什么:我刚刚更换TextArea使用TextFlow,改编的代码,这就是它.没有其他的.

当我加载一个相当大的文本文件时,布局变得混乱.在加载之前,布局很好:

在加载之前

现在我尝试加载一个足够长的文本文件,使其不适合TextFlow它,并且...这就是我得到的:

在此输入图像描述

使用时我没有这样的问题TextArea.后者将自动"插入"(如果这是正确的单词)垂直和水平滚动条,并将保留我的MenuBar完整,非常感谢.

但是TextArea我不会只强调文本的一部分......所以我需要一个TextFlow.

我如何做一个TextFlow"布局明智" 的表现TextArea

Jam*_*s_D 7

TextArea实现自己的滚动条,为它们分配空间,并在需要时自动显示它们.TextFlow实际上只是一个简单的布局管理器,并没有这样做.要在TextFlow需要时放置滚动条,只需将其包裹TextFlowScrollPane:

<ScrollPane>
    <TextFlow fx:id="inputText" ... />
</ScrollPane>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您实际上可以更好地控制滚动条.例如,你可以做到

<ScrollPane fitToWidth="true">
Run Code Online (Sandbox Code Playgroud)

然后内容(TextFlow在这种情况下)将其宽度设置为滚动窗格的宽度(因此永远不会有水平滚动条,只有垂直滚动条).该ScrollPaneJavadoc中列出的所有属性,当然.