JavaFX 3D
Richard Bair
richard.bair at oracle.com
Wed Jun 6 14:01:05 PDT 2012
Hi Tom,
Here is an example application. Run it, and move the slider. You can see several differences between the left & right examples. You can switch between "createContent" and "createContent2" for different examples of the problems.
Richard
package javafxapplication1;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
*
* @author richardbair
*/
public class OpacityTest extends Application {
@Override public void start(final Stage primaryStage) throws Exception {
final Parent a = createContent2();
final Parent b = createContent2();
HBox hbox = new HBox();
hbox.getChildren().addAll(a, b);
final Slider slider = new Slider();
slider.setMin(0);
slider.setMax(1);
slider.setValue(1);
slider.valueProperty().addListener(new InvalidationListener() {
@Override public void invalidated(Observable arg0) {
a.setOpacity(slider.getValue());
setOpacity(b, slider.getValue());
}
});
VBox root = new VBox();
root.setPadding(new Insets(5));
root.getChildren().addAll(hbox, slider);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setResizable(false);
}
private Parent createContent() {
Rectangle cyan = new Rectangle(400, 400, Color.CYAN);
Rectangle magenta = new Rectangle(300, 300, Color.MAGENTA);
Rectangle yellow = new Rectangle(200, 200, Color.YELLOW);
Rectangle black = new Rectangle(100, 100, Color.BLACK);
StackPane stackPane = new StackPane();
stackPane.getChildren().addAll(cyan, magenta, yellow, black);
return stackPane;
}
private Parent createContent2() {
TabPane tabPane = new TabPane();
tabPane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);
Tab t1 = new Tab("First");
Tab t2 = new Tab("Second");
tabPane.getTabs().addAll(t1, t2);
StackPane p1 = new StackPane();
Button b1 = new Button("Button1");
b1.setPrefSize(100, 100);
b1.setEffect(new DropShadow());
p1.getChildren().add(b1);
t1.setContent(p1);
StackPane p2 = new StackPane();
Button b2 = new Button("Button2");
b2.setPrefSize(100, 100);
b2.setEffect(new DropShadow());
p2.getChildren().add(b2);
t2.setContent(p2);
tabPane.setPrefSize(400, 400);
StackPane stackPane = new StackPane();
stackPane.getChildren().addAll(tabPane);
return stackPane;
}
private void setOpacity(Parent parent, double value) {
for (Node n : parent.getChildrenUnmodifiable()) {
if (n instanceof Parent) {
setOpacity((Parent)n, value);
}
n.setOpacity(value);
}
}
public static void main(String[] args) {
launch(args);
}
}
More information about the openjfx-dev
mailing list