Javafx 文本区域禁用滚动条

标签 java javafx scroll textarea javafx-8

目前,我正在为一种编程语言制作 lw 解释器。 http://www.muppetlabs.com/~breadbox/bf/ 无论如何,我正在尝试实现一个文本区域,但我希望隐藏滚动条。我已经查看了多个教程来执行此操作,但它们似乎都不起作用。这是我的 fxml 窗口的代码

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<SplitPane dividerPositions="0.6231155778894473" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="interpreter.Window">
  <items>
    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0">
         <children>
            <HBox layoutX="188.0" layoutY="81.0" prefHeight="262.0" prefWidth="599.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="-1.0" AnchorPane.topAnchor="0.0">
               <children>
                  <Pane prefHeight="200.0" prefWidth="200.0">
                     <children>
                        <Button fx:id="executor" layoutX="64.0" layoutY="64.0" mnemonicParsing="false" onAction="#onExecute" text="Execute" />
                        <TextField fx:id="input" layoutX="15.0" layoutY="105.0" promptText="input" />
                        <ComboBox fx:id="byteSize" layoutX="23.0" layoutY="153.0" prefWidth="150.0" promptText="Byte Size" />
                        <TextField fx:id="bytes" alignment="CENTER_RIGHT" layoutX="25.0" layoutY="205.0" prefHeight="27.0" prefWidth="91.0" promptText="Bytes" text="30000" />
                        <Text layoutX="39.0" layoutY="41.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Control Center" textAlignment="CENTER">
                           <font>
                              <Font size="17.0" />
                           </font>
                        </Text>
                        <Text layoutX="122.0" layoutY="222.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Bytes" />
                        <Line endX="100.0" layoutX="98.0" layoutY="261.0" startX="-100.0" />
                     </children>
                  </Pane>



                    <TextArea fx:id="errorLog" disable="true" editable="false" prefHeight="262.0" prefWidth="38.0" style="-fx-text-fill: #ff0000" />
                     //this is the one where I want the scroll bars hidden



                  <TextArea fx:id="code" prefHeight="262.0" prefWidth="361.0" promptText="Code" HBox.hgrow="ALWAYS" />
               </children>
            </HBox>
         </children>
      </AnchorPane>
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
         <children>
             <TextArea fx:id="output" disable="true" editable="false" layoutX="76.0" layoutY="-60.0" prefHeight="166.0" prefWidth="598.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
         </children>
      </AnchorPane>
  </items>
</SplitPane>

我已经指定了我要隐藏哪一个的滚动条。有人对此有任何见解吗?谢谢。

最佳答案

这可以通过在内部 ScrollPane 上设置水平+垂直滚动条策略来完成。我目前不确定这是否可以通过 FXML 或 Java API 完成,但是可以通过 CSS 实现。

参见 CSS guide on ScrollPane

#errorLog .scroll-pane {
    -fx-hbar-policy: never;
    -fx-vbar-policy: never;
}

这假定了 TextArea 的 CSS 子结构,但这在 official CSS gudie for TextArea 中有明确定义。

scroll-pane — ScrollPane
    content — Region

如果您还没有使用 CSS,则需要定义一个 CSS 文件并将其添加到场景或 FXML 中。有关如何执行此操作的信息,请参阅 Styling UI Controls with CSS .

关于Javafx 文本区域禁用滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47786074/

相关文章:

java - 比较器应该每次都实例化还是只实例化一次?

java - Oracle WebLogic EAR Extensions 方面未添加到我的 Web 服务中

java - 不断检查时间线是否停止 - 触发操作

html - 水平滚动打印表格

java - 无法使用 webdriver 将文件上传到 Box.com

java - 在JAVA中对字符串使用Contains方法

java - 如何根据If Else函数刷新GridPane?

java - 在 FXML 文档中使用自定义控件

c# - 文本框中的中间按钮滚动的东西

cocoa - 如果另一个应用程序收到滚动事件,是否有可能收到通知?