Tuesday, December 30, 2008

Z-Order is supported in JavaFX !

While writing some of the samples in which we have to play with images, we sometimes has to manage the depth of the images. Like for the Carousel example, every image has a depth. In that example, actually images are not overlapping with each other, so we never need to write the Z-Order concept. But if someone want to write a Carousel or some application in which Images are residing over other images, we need to set the Z-order of Images. Z-Order in literal term means depth-ness of images. JavaFX gracefully provide API's to set the Z-order of images. With a simple call, you can set the images toFront or toBack features.


In this example, I have taken 3 images and try to set the depth-ness of images on the event of Buttons.



First Image on Top Second Image on Top





Third Image on Top


Here is the code to set the Z-Order :


package zorder;

import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.Rectangle;
import javafx.scene.input.MouseEvent;
import javafx.ext.swing.SwingButton;

var im1 = ImageView {
x: 100
y: 100
image: Image {
url: "{__DIR__}im1.PNG"
}
opacity: 0.8
};

var im2 = ImageView {
x: 130
y: 130
image: Image {
url: "{__DIR__}im2.PNG"
}
opacity: 0.8
};

var im3 = ImageView {
x: 160
y: 160
image: Image {
url: "{__DIR__}im3.PNG"
}
opacity: 0.8
};

var gp = Group {
content:[
im1, im2,im3
]

}
Stage {
title: "Application title"
width: 400
height: 400
scene: Scene {
fill: Color.BLACK
content: [
gp,
SwingButton {
translateX: 10
translateY: 10
text: "Image 1"
action: function() {
im1.toFront();
}
}
SwingButton {
translateX: 90
translateY: 10
text: "Image 2"
action: function() {
im2.toFront();
}
}
SwingButton {
translateX: 170
translateY: 10
text: "Image 3"
action: function() {
im3.toFront();
}
}
]
}
}




From next blog, I will use applet or JNLP in place of images, as suggested by Dmitry in last blog. Pictures make it bulky and uneasy to load. But I was getting some problem in deploying the application on Sun blog which will be rectified soon.

1 comment:

Anonymous said...

我的站點介紹:情趣用品,情趣用品,情趣用品,情趣用品情趣用品,
情趣用品,
情趣用品,
情趣用品,
情趣用品,
情趣用品 來看看 賣克

這一家的中古車的性能很好
室內設計這是我找過最好的一家唷!

室內設計這家很好!

保健食品代工,素食膠囊,順傑

你需要買雨傘,這裡有一把優良的雨傘讓你的,制服不會被淋濕唷!制服

清境農場
SEO排名真好玩耶
哪有好的網站設計公司
室內設計也太多家了吧
香舖拜拜都要去買香耶
你的廣告是哪一家廣告設計公司處理的?