1

I would like to apply ControlsFx decorations in a TableCell and as such would like to apply them to a Label.

This following does NOT apply the decoration to the Label. Should it?

import org.controlsfx.control.decoration.Decorator;
import org.controlsfx.control.decoration.GraphicDecoration;
import org.controlsfx.validation.decoration.GraphicValidationDecoration;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class LabelDecoration extends Application {

    private static final Image REQUIRED_IMAGE = new Image(GraphicValidationDecoration.class.getResource("/impl/org/controlsfx/control/validation/required-indicator.png").toExternalForm()); //$NON-NLS-1$

    @Override
    public void start(Stage primaryStage) throws Exception {

        Label label = new Label("Test");

        Node requiredDecoration = new ImageView( REQUIRED_IMAGE );
        Decorator.addDecoration( label, new GraphicDecoration( requiredDecoration, Pos.TOP_LEFT ));

        primaryStage.setScene( new Scene( label, 100, 100 ));   
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch( args );
    }

}
stacktrace
  • 547
  • 1
  • 6
  • 19

1 Answers1

2

The Decorator tries to install a DecorationPane into the scene, which does not exist yet in your case.

Wrap the line Decorator.addDecoration(...) in a Platform.runLater(...) and it will work.

AKreisel
  • 58
  • 1
  • 7