我有使用FXML构建GUI的JavaFX应用程序.
当这个应用程序启动时,我需要有ListView,它有一些值,例如,从数据库加载.那么,我该怎么做呢?
我知道如何创建应用程序,在用户单击按钮后将项目加载到ListView,或类似的东西(FXML中的"onAction"属性).但这不适合我,因为我需要将项目自动加载到ListView.
我尝试使用FXML和CSS更改app构建中的单选按钮大小.我使用的是sceneBuilder.
谢谢你的帮助 !
这是我的单选按钮的实际CSS代码:
.radio-button .radio{
-fx-border-width : 1px ;
-fx-border-color : #000 ;
-fx-background-color : white ;
-fx-background-image : null ;
-fx-border-radius : 15px ;
-fx-height : 15px ; /* Not working */
height : 5px ; /* Not working */
}
.radio-button .radio:selected{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:armed{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:determinate{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:indeterminate{
-fx-background-color : …Run Code Online (Sandbox Code Playgroud) 我是FXML的新手,我正在构建一个应用程序.现在我遇到了一个我无法解决的问题.
我在FXML中定义了一个组合框,并在控制器类中创建了necesarry关联.但我想在这个组合框中添加图像.
仍然经过几个小时的谷歌搜索,我仍然无法解决这个问题.
你能帮助我一个关于如何实现目标的"简单"例子吗?
非常感谢!
我目前的代码是:(确定有一种更简单的方法可以做到这一点,但它有效!)
ImageView img1 = new ImageView("Layout/nl.png");
ImageView img2 = new ImageView("Layout/en.png");
AnimalBoxLanguage.getItems().addAll(img1, img2);
AnimalBoxLanguage.setCellFactory(new Callback<ListView<ImageView>, ListCell<ImageView>>() {
@Override public ListCell<ImageView> call(ListView<ImageView> p) {
return new ListCell<ImageView>() {
private final ImageView rectangle;
{
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
rectangle = new ImageView();
}
@Override protected void updateItem(ImageView item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
rectangle.setImage(item.getImage());
setGraphic(rectangle);
}
}
};
}
});
Run Code Online (Sandbox Code Playgroud) 我刚开始使用fxml,这似乎是一个非常酷的想法,除了我很难让它运行起来.据说我可以使用一个很好的标记语言来布局我的GUI,我可以通过CSS设置元素的样式.所以我的GUI上有一个标签,我希望它周围有一个坚固的黑色边框,宽度= 1.看起来这应该是直截了当的 - 我在教程等中看到的适应示例,我执行以下操作:
<Label text="sample text" style="-fx-border-width: 1; -fx-border-style: solid;" />
Run Code Online (Sandbox Code Playgroud)
但它不起作用.没有边框出现.在场景生成器中,属性检查器中有一个标记为"样式"的文本框,我可以看到我应用的样式出现在那里,但是我看不到边框.
我在俯瞰什么?
我是javaFX的新手.我使用fxml创建了一个注册表单.现在我想实现字段验证功能.我正在尝试实现TextField的验证,但我仍然没有得到它.请任何人都可以帮助我.
谢谢Naresh
我是JavaFX的新手,我在JavaFX中遇到了2-3种设计UI的方法.
哪个更好?为什么?
我希望我的所有组件(TextFields,标签等)都保持在固定大小的中心.我在场景构建器中制作它并且当我看到预览时它可以工作,但是当我启动它时,当我调整它时,组件不会留在中心.
请看这里的图片:http://postimg.org/image/r42kvvfbf/
FXML文件:
<AnchorPane id="AnchorPane" fx:id="root" maxHeight="-1.0" maxWidth="-1.0" minHeight="400.0" minWidth="600.0" prefHeight="-1.0" prefWidth="-1.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="myController">
<children>
<GridPane alignment="CENTER" prefHeight="-1.0" prefWidth="-1.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="-1.0" prefWidth="-1.0" spacing="10.0" GridPane.columnIndex="0" GridPane.rowIndex="0">
<children>
<Label text="ID number" />
<TextField fx:id="id" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="210.0" promptText="" />
<Label text="Password" />
<TextField fx:id="password" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="210.0" promptText="" />
<HBox id="HBox" alignment="CENTER" spacing="5.0">
<children>
<Button mnemonicParsing="false" onAction="#loginAction" text="????" textAlignment="CENTER" textOverrun="ELLIPSIS" />
</children>
</HBox>
</children>
<padding>
<Insets bottom="20.0" left="20.0" …Run Code Online (Sandbox Code Playgroud) 你好Stackeroverflowers,
我想问一下如何更换RadioButton Dot?我需要定义3个具有3种不同颜色的RadioButton来显示状态.我必须与Css合作吗?如果有人能告诉我我怎么能意识到这一点,那将是完美的吗?
一个例子是:
@FXML
public RadioButton redState = new RadioButton();
.
.
.
redState.setDotColor(red);
Run Code Online (Sandbox Code Playgroud)
或者在Fxml中定义Color静态:
style="-fx-dot-color: rgb(255,0,0);"
Run Code Online (Sandbox Code Playgroud)
我希望每个人都理解我的计划.它只是在javafx RadioButton中着色Dot.
我很感谢每一个答案.
StackPane layoutY="70.0" prefHeight="479.0".我想在Java文件中创建值(70.0)和(479.0)静态,以便我可以将它们用于其他文件.
这可能吗?
I'm using Scene Builder (v11.0.0) to create FXML files for scenes in JavaFX (v12) but, despite instructing all containers to USE_COMPUTED_SIZE for the preferred widths and heights, the rendered scenes (as seen in Scene Builder and also when run as a JavaFX application which loads those FXML files) are being clipped at the right and bottom edges so that bits of nodes are chopped off.
And in Scene Builder it seems that the renderer must know that the scene won't …