【问题标题】:Why JavaFX blurs controls and how to fix it?为什么 JavaFX 会模糊控件以及如何修复它?
【发布时间】:2017-01-31 05:11:52
【问题描述】:

我有这种简单形式的 JavaFX 应用程序,其中包含两个没有样式属性的 TextArea:

查看表单时,我看到:

FXML 代码在这里:

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

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


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TitledPane animated="false" prefWidth="300.0" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <content>
            <TextArea prefHeight="200.0" prefWidth="200.0" />
         </content>
      </TitledPane>
      <SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="300.0" AnchorPane.topAnchor="0.0">
        <items>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
               <children>
                  <TitledPane animated="false" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <content>
                      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                           <children>
                              <TextArea prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="-10.0" AnchorPane.leftAnchor="-10.0" AnchorPane.rightAnchor="-10.0" AnchorPane.topAnchor="-10.0" />
                           </children>
                        </AnchorPane>
                    </content>
                  </TitledPane>
               </children>
            </AnchorPane>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
        </items>
      </SplitPane>
   </children>
</AnchorPane>

第一个 TextArea 中的文本模糊。为什么会发生以及如何解决?

【问题讨论】:

  • 也许您在 TextArea 中设置了 Prompt Text 而不是 Text?还是在 Scene Builder 中设置模糊效果?
  • 在您的问题中发布 FXML
  • MBec,不,我没有使用任何效果,也没有设置提示文本。 James_D,为你添加 FXML 代码

标签: javafx scenebuilder


【解决方案1】:

当您使用此组合时会出现问题:TitledPane -&gt; AnchorPane(嵌入到 AnchorPane 中的元素无关紧要)。当您使用 AnchorPane 约束工具时,嵌套元素会获取 Width、Height、LayoutBounds、BoundsInLocal 和 BoundsInParent 值的伪影。这些伪影会影响模糊。

没有约束:

有一些限制:

为了解决问题,不要使用组合 TitledPane-&gt; AnchorPane 或不要使用工具 AnchorPane Constraints。

【讨论】:

    【解决方案2】:

    您已将 TextArea 包装在另一个 AnchorPane 中的 SplitPane 中。如果你删除模糊就消失了。我不知道为什么,但我可以让它与这段代码一起工作。

    <?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="400.0"
                prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
        <TitledPane animated="false" prefWidth="300.0" text="test2" AnchorPane.bottomAnchor="0.0"
                    AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <TextArea prefHeight="200.0" prefWidth="200.0"/>
        </TitledPane>
        <SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0"
                   AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="300.0"
                   AnchorPane.topAnchor="0.0">
            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                <TitledPane animated="false" text="test" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
                            AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                        //deleted AnchorPane here
                        <TextArea prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="-10.0"
                                  AnchorPane.leftAnchor="-10.0" AnchorPane.rightAnchor="-10.0"
                                  AnchorPane.topAnchor="-10.0"/>
                </TitledPane>
            </AnchorPane>
            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
        </SplitPane>
    </AnchorPane>
    

    【讨论】:

    • 感谢您的回答。我知道模糊是由于高嵌入。这个例子是综合生成的以显示问题。我想知道为什么会这样。
    • This 在发生模糊时提供更多洞察力。还是不知道是什么原因。
    猜你喜欢
    • 2011-10-21
    • 2022-01-09
    • 1970-01-01
    • 2018-07-12
    • 2018-02-23
    • 2022-11-20
    相关资源
    最近更新 更多