“场景”构建器上禁用“标签字体和文本填充” [英] Label Font and Text Fill disabled on Scene builder

查看:142
本文介绍了“场景”构建器上禁用“标签字体和文本填充”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Scene Builder和JavaFXML的新手。当我在我的Anchor Pane中添加一个Label时,我无法更改Text的字体和它的颜色。这两个选项都是灰色的,旁边有这个CSS标题。
我怎么能禁用这些选项?对于按钮也是如此。

I'm fairly new to Scene Builder and JavaFXML. When I added a Label to my Anchor Pane, I couldn't change the Font of the Text and it's colour. Both the options have been greyed out and there's this CSS heading next to it. How can I not disable those options? This is the same case for the buttons too.

FXML文件:

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

<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="672.0" prefWidth="176.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane prefHeight="188.0" prefWidth="176.0" style="-fx-background-color: #1c94d900;">
         <children>
            <Label fx:id="StudentUSN" layoutX="15.0" layoutY="145.0" prefHeight="24.0" prefWidth="146.0" />
         </children>
      </AnchorPane>
      <VBox prefHeight="464.0" prefWidth="176.0">
         <children>
            <JFXButton fx:id="b1" prefHeight="44.0" prefWidth="176.0" style="-fx-background-color: #1156cf;" text="Attendance" />
            <JFXButton fx:id="b2" disable="true" prefHeight="44.0" prefWidth="176.0" style="-fx-background-color: #1156cf;" text="Clubs" />
            <JFXButton fx:id="b3" disable="true" prefHeight="48.0" prefWidth="176.0" style="-fx-background-color: #1156cf;" text="Results" />
            <JFXButton fx:id="b4" disable="true" prefHeight="48.0" prefWidth="176.0" style="-fx-background-color: #1156cf;" text="Feedback" />
         </children>
      </VBox>
   </children>
</VBox>


推荐答案

将外部CSS应用于FXML

给出简单的测试:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
   <children>
      <Label layoutX="448.0" layoutY="49.0" text="Label" />
   </children>
</AnchorPane>

和一个单独的css文件:

and a separated css file:

.label {
    -fx-font-family: Roboto;
    -fx-text-fill: grey;
}

如果没有在FXML文件中捆绑CSS文件,可以将其添加到Scene Builder中,因此它将应用样式预览。

Without bundling a CSS file in the FXML file, you can add it to Scene Builder, so it will apply the styling to the preview.

这可以从预览 - >场景样式表 - >添加样式表...

应用样式表后,可以锁定某些设置,这意味着该值已在css文件中设置。

Once the style sheet is applied, some settings can be locked, meaning that the value is already set in the css file.

场景构建器首选项

Scene Builder有一个内部首选项系统,可以跟踪最近使用的FXML文件的不同设置。

Scene Builder has an internal preferences system that keeps track of different settings for the recent FXML files used.

对于它保存的每个文件:

For each file it saves:


  • name

  • path

  • X,Y,宽度和高度

  • divider pos itions,visible panes

  • ...

  • 以及添加到FXML文件的外部样式表文件。

  • name
  • path
  • X, Y, width and height
  • divider positions, visible panes
  • ...
  • and the external style sheets files added to the FXML file.

这意味着如果您关闭Scene Builder,几天后再打开,当打开相同的FXML文件时,将恢复并应用所有这些首选项。

This means that if you close Scene Builder, and you come back a few days later, when opening the same FXML file, all those preferences will be restored and applied.

在OP发布的情况下,由于某些未知原因,css文件已被删除,但锁仍然被应用。

In the case posted by the OP, for some unknown reasons, the css file was removed, but the lock was still applied.

因此,在这种情况下的快速修复只是编辑首选项文件,并删除文档条目。它的所有设置都将丢失,但没有什么重要的。

So the quick fix in this case is just editing the preferences file, and removing the document entry. All its settings will be lost, but there is nothing really important there.

查找首选项文件

在Mac上,可在此处找到该文件:

On Mac, the file can be found here:

/Users/<user>/Library/Preferences/com.oracle.javafx.plist

并且可以使用Xcode进行编辑。

and it can be edited with Xcode.

在Windows上,可以在注册表中的此项找到首选项:

On Windows, the preferences can be found at this key in the registry:

HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\oracle\javafx

并且可以使用Regedit进行编辑。

and it can be edited with Regedit.

在Linux上(可能)

On Linux (possibly)

${user.home}/.java/.userPrefs/...

这篇关于“场景”构建器上禁用“标签字体和文本填充”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆