エラーアイコン描画のサンプル
エラーアイコンを描画したい場合に利用できるサンプルです。任意のサイズで表示でき、また画像ファイルを同梱しないでよいのも魅力です。
package sample; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.effect.Light; import javafx.scene.effect.Lighting; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.Line; import javafx.stage.Stage; /** * エラーアイコンを描画する JavaFX 2 サンプル */ public class Sample001 extends Application { void drawErrorIcon(final int zoomRate, final Group root) { final Circle circle = new Circle(5 * zoomRate, 5 * zoomRate, 5 * zoomRate); root.getChildren().add(circle); circle.setFill(Color.RED); { final Light.Spot light = new Light.Spot(); light.setX(0); light.setY(0); light.setZ(10 * zoomRate); final Lighting lighting = new Lighting(); lighting.setLight(light); circle.setEffect(lighting); } { final Line line = new Line(3 * zoomRate, 3 * zoomRate, 7 * zoomRate, 7 * zoomRate); line.setFill(null); line.setStroke(Color.WHITE); line.setStrokeWidth(1.2 * zoomRate); root.getChildren().add(line); } { final Line line = new Line(7 * zoomRate, 3 * zoomRate, 3 * zoomRate, 7 * zoomRate); line.setFill(null); line.setStroke(Color.WHITE); line.setStrokeWidth(1.2 * zoomRate); root.getChildren().add(line); } } @Override public void start(final Stage primaryStage) { primaryStage.setTitle("Draw error icon"); final Group root = new Group(); drawErrorIcon(10, root); primaryStage.setScene(new Scene(root, 200, 200)); primaryStage.show(); } public static void main(final String[] args) { launch(args); } }