How to create multiple javafx controllers with different fxml files?

Use FXML as components by using a custom java class as fx:root and as fx:controller of your FXML file: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm To do so, you need to call in the constructor of your custom java class FXMLLoader which will load your FXML. The advantage is to change the way FXML load components. The classic way to … Read more

JavaFX Project Structure

IMHO, you shouldn’t create package’s depending on your views. My approach towards such applications A package for corresponding controllers of these views Different packages for service(business) and dao(persistence) layer, if exists A directory for resources such as images, css etc A directory for FXML files called view in the resources src/main ├──java ├── controllers ├──Screen1controller.java … Read more

Styling a JavaFX 2 button using FXML only – How to add an image to a button?

Solution using only fxml As tarrsalah points out, css is the recommended way of doing this, though you can also do it in fxml if you prefer: <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?> <AnchorPane id=”AnchorPane” maxHeight=”-Infinity” maxWidth=”-Infinity” minHeight=”-Infinity” minWidth=”-Infinity” prefHeight=”400.0″ prefWidth=”600.0″ xmlns:fx=”http://javafx.com/fxml”> <children> <Button layoutX=”104.0″ layoutY=”81.0″ mnemonicParsing=”false” … Read more

How do I add margin to a JavaFX element using CSS?

Probably really late to the party, but I use another approach which might be helpful for others too. There’s no -fx-margin: 5px; CSS property for JavaFX buttons, but you can workaround the behaviour with a combination of -fx-padding, -fx-border-insets and -fx-background-insets. For example a button with a 5px margin. .button-with-margin { -fx-padding: 5px; -fx-border-insets: 5px; … Read more

How to switch scenes in JavaFX

I wrote this controller to keep track of the different scenegraphes. public class ScreenController { private HashMap<String, Pane> screenMap = new HashMap<>(); private Scene main; public ScreenController(Scene main) { this.main = main; } protected void addScreen(String name, Pane pane){ screenMap.put(name, pane); } protected void removeScreen(String name){ screenMap.remove(name); } protected void activate(String name){ main.setRoot( screenMap.get(name) ); … Read more

How to control the JavaFX Tooltip’s delay?

I use the next hack for this via Reflection public static void hackTooltipStartTiming(Tooltip tooltip) { try { Field fieldBehavior = tooltip.getClass().getDeclaredField(“BEHAVIOR”); fieldBehavior.setAccessible(true); Object objBehavior = fieldBehavior.get(tooltip); Field fieldTimer = objBehavior.getClass().getDeclaredField(“activationTimer”); fieldTimer.setAccessible(true); Timeline objTimer = (Timeline) fieldTimer.get(objBehavior); objTimer.getKeyFrames().clear(); objTimer.getKeyFrames().add(new KeyFrame(new Duration(250))); } catch (Exception e) { e.printStackTrace(); } }

FXML full reference?

FXML Reference Introduction to FXML describes the syntax and usage patterns of the markup and is important to study when learning FXML. It does not define all elements usable in FXML. There will never be a full reference (nor xml schema) for FXML as it works by reflecting on Java classes in the classpath and … Read more

Customize ListView in JavaFX with FXML

I understand your question. There are mainly two ways to set items in a Listview: 1. Create the ObservableList and set the items of the ListView with the ObservableList (listView.setItems(observableList)). 2. Use the setCellFactory() method of the ListView class. You would prefer to use the setCellFactory() method, because this approach simplies the process as well … Read more