嗨,我无法将图标添加到我的jfxtextfield中,但未找到任何有关 有人可以帮忙吗?
fxml:
private static class Example {
public String getValue() {
return null;
}
}
@Test
public void testReturnChain() throws Exception {
Example example = new Example();
Example mockExample = PowerMockito.spy(example);
PowerMockito.doReturn("firstValue", "secondValue").when(mockExample, "getValue");
assertEquals("firstValue", mockExample.getValue());
assertEquals("secondValue", mockExample.getValue());
assertEquals("secondValue", mockExample.getValue());
}
我的控制器:
<VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox fx:id="boxLogo" alignment="CENTER" prefHeight="100.0" prefWidth="300.0">
<children>
<FontAwesomeIconView glyphName="HOME" size="50">
<fill>
<LinearGradient endX="1.0" endY="1.0" startY="0.49047619047619045">
<stops>
<Stop color="#0d96ff" />
<Stop color="#010f1b" offset="1.0" />
</stops>
</LinearGradient>
</fill>
</FontAwesomeIconView>
</children>
</HBox>
<GridPane fx:id="boxField" alignment="CENTER" prefHeight="222.0" prefWidth="300.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="131.0" minHeight="10.0" prefHeight="108.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="142.0" minHeight="10.0" prefHeight="107.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="142.0" minHeight="10.0" prefHeight="107.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<JFXTextField fx:id="userTxt" alignment="CENTER" focusColor="#1cffb3" labelFloat="true" maxWidth="-Infinity" prefWidth="200.0" text="Digite o seu Login" unFocusColor="#00fffb" GridPane.halignment="CENTER" />
<JFXTextField alignment="CENTER" focusColor="#00ff77" maxWidth="-Infinity" prefWidth="200.0" text="Digite a sua senha" unFocusColor="#00fffb" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
<JFXCheckBox text="Lembrar Usuario" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<GridPane.margin>
<Insets right="50.0" />
</GridPane.margin>
</JFXCheckBox>
</children>
</GridPane>
<HBox fx:id="boxButtons" alignment="TOP_CENTER" prefHeight="100.0" prefWidth="300.0" spacing="30.0">
<children>
<JFXButton buttonType="RAISED" prefHeight="25.0" prefWidth="86.0" ripplerFill="#09fff7" style="-fx-background-color: #0DA5E2;" text="Entrar" textFill="WHITE" textOverrun="CLIP">
<font>
<Font name="Arial" size="12.0" />
</font>
</JFXButton>
</children>
</HBox>
</children>
</VBox>
我想将我创建的图标添加到textfiedl userTxt中 我不知道这是可以通过控制器还是仅通过CSS完成?
我发现通过css,但是我需要添加一个带有照片的文件夹才能工作,我想可以通过图标来做到这一点吗?
答案 0 :(得分:0)
我建议将此添加到您的控制器中:
myJFXTextField.setstyle("-fx-background
image:url('http://icons.iconarchive.com/icons/rockettheme/halloween/32/pumpkin-
icon.png');");
这在您的CSS
中.text-field {
-fx-background-repeat: no-repeat;
-fx-background-position: right center;
-fx-font-size: 20;
}
您可以使用路径或URL