标签上的ControlsFx装饰

时间:2016-02-11 14:32:24

标签: javafx controlsfx

我想在TableCell中应用ControlsFx装饰,因此希望将它们应用于Label。

以下内容不适用于标签的装饰。应该吗?

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 );
    }

}

1 个答案:

答案 0 :(得分:1)

装饰器尝试将 DecorationPane 安装到场景中,但在您的情况下还不存在。

Decorator.addDecoration(...)行包装在 Platform.runLater(...)中,它会起作用。