学習JavaFX(五):シーン補助類

5067 ワード

javafx.scene.layoutバッグを覚えていますか?それはシーンレイアウトを定義するためのツールバッグです。本論文で紹介したColor、Font、Image、ImageViewは、これらの種類はさまざまなレベル、角度から結点をサポートする表現形式で、比較的簡単ですが、功は大丈夫です。これらの種類はjavafx.sceneパッケージのサブバッグの下に定義されています。
Color(色)
関係を引き継ぐ
java.lang.Object
    javafx.scene.paint.Paint
        javafx.scene.paint.Color
プロトタイプ宣言
public final class Color extends Paint implements Interpolatable<Color>
作成方法
Color(double red, double green, double blue, double opacity)
インスタンスを作成
/** New an instance. */
Color color = new Color(..);

/** Throuth color() method to create an instance. */
Color color = Color.color(..);
使用例
scene.setFill(Color.BLACK);
フォント
関係を引き継ぐ
java.lang.Object
    javafx.scene.text.Font
プロトタイプ宣言
public final class Font extends Object
作成方法
Font(double size)
Font(String name, double size)
インスタンスを作成
/** New an instance. */
Font font = new Font(..)

/** Throuth font() method to create an instance. */
Font font = Font.font(..);
使用例
label.setFont(Font.font(12));
Image(写真)、ImageView(写真デモンストレーション)
関係を引き継ぐ
java.lang.Object
    javafx.scene.image.Image
java.lang.Object
    javafx.scene.Node
        javafx.scene.image.ImageView
プロトタイプ宣言
public class Image extends Object
@DefaultProperty(value="image")
public class ImageView extends Node
構造方法(部分)
Image:
Image(String url)
Image類サポートBMPGIFjpegpngフォーマットの画像
ImageView
ImageView()
ImageView(Image image)
ImageView(String url)
どの画像にも関連しないImageViewを作成することができますし、関連するImageを作成しながら指定することもできます。ImageView対象は結点類であり、Pane類の例での立上用getChildren().add(imageView)追加が可能である。
使用例
pane.getChildren().add(new ImageView("demo.png"));