为什么JavaFX会模糊控制以及如何解决它?

时间:2017-01-31 05:11:53

标签: javafx scenebuilder

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

enter image description here

查看表单时,我看到了:

enter image description here

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中的文字模糊不清。为什么会发生以及如何解决?

2 个答案:

答案 0 :(得分:2)

使用此组合时会出现问题:TitledPane -> AnchorPane(将哪些元素嵌入到AnchorPane中无关紧要)。当您使用AnchorPane Constraints工具时,嵌套元素会获得Width,Height,LayoutBounds,BoundsInLocal和BoundsInParent值的工件。这些伪影会影响模糊。

没有约束: enter image description here

有约束: enter image description here

要解决此问题,请不要使用组合TitledPane-> AnchorPane或不使用工具AnchorPane约束。

答案 1 :(得分:1)

您已将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>