fxml

Adding a TilePane instantiated in .java files to FXML

泄露秘密 提交于 2019-12-31 04:20:15
问题 I'm trying to add a TilePane with ImageView children to a scene in JavaFX. Currently, my FXML is loading an empty TilePane. The current FXML line that i have making the TilePane is <TilePane id="MapPane" fx:id="mapPane" layoutX="3.0" layoutY="0.0" prefColumns="9" prefHeight="560.0" prefTileHeight="112.0" prefTileWidth="112.0" prefWidth="1277.0" visible="true"\> where mapPane is the name of the variable in my .java file controller: /* * To change this template, choose Tools | Templates * and

Using Unicode characters with JavaFX

为君一笑 提交于 2019-12-31 01:50:27
问题 I've been playing around with swing for some time and decided to check out FX now. So far I'm finding it a lot easier and more fun to work with as compared to swing but I've run into a small speed bump and after hours of looking around I just can't find a solution. I am unable to use \u when I try to add it through the fxml file It works fine if I don't use the fxml but I want to use the scene builder as it is more convenient. Here's the small piece of code: <?xml version="1.0" encoding="UTF

Is it possible to set a JavaFX static property in CSS?

夙愿已清 提交于 2019-12-31 01:50:25
问题 Sample FXML with the BorderPanel.alignment "static property": <BorderPane> <top> <Label text="My Label" BorderPanel.alignment="CENTER"/> </top> </BorderPane> The CSS-supported version: <BorderPane stylesheets="Style.css"> <top> <Label text="My Label" styleClass="labelClass"/> </top> </BorderPane> Style.css would be: .labelClass { -fx-borderpanel-alignement: center } 回答1: For JavaFX versions 2.0 to 2.2 => no you cannot set the static layout properties via css. You can create a feature request

Creating a large body of text with different styles - JavaFX FXML

老子叫甜甜 提交于 2019-12-30 22:51:35
问题 In the fxml class of my JavaFx application I want to add a large body of text using minimal components (instead of adding multiple labels per line). I would also like to create varying styles of text in the same component. What component should I use (e.g TextArea) and how would I go about create multiple styles inside it (using css). 回答1: Use a TextFlow and add Text to it. You can style individual Text component with different style using css on them. Complete example : import javafx

Multiple controller for one FXML file

夙愿已清 提交于 2019-12-30 10:00:19
问题 I have one fxml file controlled by one controller. I want to separate the controller into multiple parts as if placed in one controller makes a long code. Unfortunately, fx:controller can only be placed in the root. Are there any suggestions for me how to separate the controller? 回答1: I recommend to create custom controls - use several smaller FXML files rather than one big FXML file. Here is the tutorial: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm 回答2: During the

Multiple controller for one FXML file

我只是一个虾纸丫 提交于 2019-12-30 10:00:07
问题 I have one fxml file controlled by one controller. I want to separate the controller into multiple parts as if placed in one controller makes a long code. Unfortunately, fx:controller can only be placed in the root. Are there any suggestions for me how to separate the controller? 回答1: I recommend to create custom controls - use several smaller FXML files rather than one big FXML file. Here is the tutorial: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm 回答2: During the

javafx change css at runtime

若如初见. 提交于 2019-12-30 08:19:52
问题 Is it possible to change css for a JavaFX application while it is running? The effect I am looking for is changing skins or themes at the click of a button. The UI is in an FXML file if that makes any difference. I have tried Scene.getStylesheets() .add(getClass().getResource(skinFileName).toExternalForm()); which has no effect. thanks 回答1: It should have the effect. Try this full demo code: public class CssThemeDemo extends Application { private String theme1Url = getClass().getResource(

How to extend custom JavaFX components that use FXML

牧云@^-^@ 提交于 2019-12-30 06:08:39
问题 How do I properly extend a custom JavaFX component to add or modify its GUI components if it uses FXML for the view? As an example scenario, suppose I use the following approach of creating a custom JavaFX component: SpecializedButton.java (Controller) package test; import java.io.IOException; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.HBox; public class SpecializedButton extends

JavaFX & FXML: how do I set the default selected item in a ChoiceBox in FXML?

試著忘記壹切 提交于 2019-12-30 06:03:09
问题 I have the following FXML: <ChoiceBox> <items> <FXCollections fx:factory="observableArrayList"> <String fx:value="2 minutes" /> <String fx:value="5 minutes" /> <String fx:value="15 minutes" /> </FXCollections> </items> </ChoiceBox> But in the GUI it just shows a ChoiceBox with a default of nothing. I would like the first element in the list to be the default, and for a choice of "null" or nothing to be prohibited. How do I accomplish this? 回答1: I added the value attribute to the ChoiceBox tag

How to populate TableView dynamically with FXML and JavaFX

柔情痞子 提交于 2019-12-30 05:27:07
问题 How do I define my table in FXML and then use my JavaFX code to populate it dynamically at runtime? 回答1: Define the TableView in the fxml file. Few things to note: the root should have a controller class associated with it. the TableView and TableColumn should have fx:id attributes specified. <BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.MyController"> <center> <ScrollPane disable="false" visible="true"> <content> <TableView fx:id="myTableView" prefHeight="-1.0"