1

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

}
4

1 に答える 1

2

Decoratorは、あなたのケースにはまだ存在しない、DecorationPaneをシーンにインストールしようとします。

行Decorator.addDecoration(...)Platform.runLater(...)でラップすると、機能します。

于 2016-04-25T06:40:36.100 に答える