Cor*_*air 5 region imageview javafx-2
我想知道如何将ImageView元素添加到JavaFx 2.1中的Region元素.
也许我得到这个元素的用法错误,但AFAIK它也是子元素的容器.
背景是,我需要定义的大小,其应显示上独立的区域中的视口的图像元素的区域,所以不能使用族元素作为容器.
使用窗格或窗格子类.
窗格区域 s到你可以添加使用儿童的getChildren() API.Pane与集团非常相似; 例如,有一个简单的api用于添加孩子,并没有明确地布局孩子的位置.它还有一个地区的方面; 例如css styleable,resize able等.Region只有一个不可修改的子列表通过他们的公共API,这意味着添加子项的唯一方法是将它们子类化(就像Pane已经为你做的那样).Region类本身实际上只是控件创建者的构建块类,而不是在正常开发期间实例化的东西.
以下是将ImageView节点添加到窗格的示例.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.*;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class RegionSample extends Application {
public static void main(String[] args) throws Exception { launch(args); }
public void start(Stage stage) throws Exception {
Pane pane = new Pane();
pane.setStyle("-fx-background-color: linear-gradient(to bottom right, derive(goldenrod, 20%), derive(goldenrod, -40%));");
ImageView iv1 = new ImageView(new Image("http://icons.iconarchive.com/icons/kidaubis-design/cool-heroes/128/Ironman-icon.png")); // Creative commons with attribution license for icons: No commercial usage without authorization. All rights reserved. Design (c) 2008 - Kidaubis Design http://kidaubis.deviantart.com/ http://www.kidcomic.net/ All Rights of depicted characters belong to their respective owners.
ImageView iv2 = new ImageView(new Image("http://icons.iconarchive.com/icons/kidaubis-design/cool-heroes/128/Starwars-Stormtrooper-icon.png"));
iv1.relocate(10, 10);
iv2.relocate(80, 60);
pane.getChildren().addAll(iv1, iv2);
stage.setScene(new Scene(pane));
stage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14806 次 |
| 最近记录: |