Javafx combobox with custom object displays object address though custom cell factory is used

Just create and set a CallBack like follows: @FXML ComboBox<User> cmbUserIds; Callback<ListView<User>, ListCell<User>> cellFactory = new Callback<ListView<User>, ListCell<User>>() { @Override public ListCell<User> call(ListView<User> l) { return new ListCell<User>() { @Override protected void updateItem(User item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); } else { setText(item.getId() + ” ” + … Read more

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

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

JavaFX: Undecorated Window

I don’t get your motivation for preliminary calling the start()-method setting a stage as undecorated, but the following piece of code should do what you want to achieve. package decorationtest; import javafx.application.Application; import javafx.stage.StageStyle; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; public class DecorationTest extends Application { public static void main(String[] args) { Application.launch(args); } @Override … Read more

How to use JavaFX 2 SDK in Eclipse?

There are two options: 1) EDIT: Since 7u35 (or smth near it) JavaFX was included into base JDK classpath so you can use JavaFX classes right away. Just set up your projects to use fx libs: JavaFX 2.0 API is pure Java. So you can create a new Java project and add sdk-path/rt/lib/jfxrt.jar to libraries … 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

JavaFX: Update of ListView if an element of ObservableList changes

There are several aspects to your question (and I’m not entirely sure which aspect is the problem 🙂 I’ll assume that your POJO is somehow notifying listeners about changes, could be by being a full-fledged JavaBean. That is, it complies with its notification contract via firing propertyChange events as needed or by some other means … Read more