[Java FX 2] Stage with rounded corners and background image
来源:互联网 发布:java订单号 编辑:程序博客网 时间:2024/05/22 14:49
转自:http://apilevel.wordpress.com/2012/10/11/java-fx-stage-with-rounded-corners-with-background-image/
I recently had a requirement of making the window of a Java FX application with rounded corners and a background image. It is simple making rounded corners but difficult with a background image filling the main stage.
After googling around i found the following discussion that says, it seems to be difficult or not possible with Java FX as of now.
https://forums.oracle.com/forums/thread.jspa?threadID=2415144
Following is a best work-around the idea is to clip the rounded corners using setClip method of the node(in the example StackPane) :
Here is an example source code [Tested with Java FX 2.2]:
=========================RoundedTest.java==========================
=========================RoundedTest.java==========================
package stage.background3;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.layout.StackPane;import javafx.scene.paint.Color;import javafx.scene.shape.Rectangle;import javafx.stage.Stage;import javafx.stage.StageStyle;public class TestStage5 extends Application {@Overridepublic void start(Stage primaryStage) {Button btn = new Button();btn.setText("Close");btn.setOnAction(new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent event) {System.exit(0);}});StackPane root = new StackPane();root.getChildren().add(btn);root.setId("ROOTNODE");Rectangle rect = new Rectangle(1024, 768);rect.setArcHeight(60.0);rect.setArcWidth(60.0);root.setClip(rect);Scene scene = new Scene(root, 1024, 768);primaryStage.initStyle(StageStyle.TRANSPARENT);scene.setFill(Color.TRANSPARENT);primaryStage.setTitle("Hello World!");primaryStage.setScene(scene);primaryStage.getScene().getStylesheets().setAll(TestStage5.class.getResource("main.css").toString());primaryStage.show();}public static void main(String[] args) {launch(args);}}
==========================main.css================================
#ROOTNODE {-fx-background-radius: 30;-fx-background-image:url('Tulips.jpg');-fx-border-radius: 30;-fx-border-width:5;-fx-border-color:blue;}
==========================main.css================================
following is is how the output looks like:
- [Java FX 2] Stage with rounded corners and background image
- NSWindow with rounded corners
- create rounded corners with CSS
- 25 Rounded Corners Techniques with CSS
- Border-radius: create rounded corners with CSS!
- IE8 Rounded Corners (With No Images)
- NiftyCube Rounded Corners Tutorial
- Rounded Image
- An Experiment in Rounded Corners
- Chart FX for JAVA (2)--------Lines AND Bar
- CSS and Round Corners: Build Boxes with Curves
- Edit Control with Icon and Background Text
- Edit Control with Icon and Background Text
- Edit Control with Icon and Background Text
- background-image
- background-image
- background ,image and repeat [and button's background implement in xp]
- java FX
- Linux .bin安装文件制作
- zju 3403 Strange Calendar III
- 百度2013年4月27日竞赛题目二
- android的IntentService
- 继续拿起CSDN博客
- [Java FX 2] Stage with rounded corners and background image
- 缅甸公民法(1982年人民议会第4号法令)罗伯特 译
- 设置SAP HANA列表的预加载(SAP HANA preload setting for column storage )
- windows phone 开发Rss阅读器教程
- 浅谈iOS 5的StoryBoard
- 实验三十 Windows Server 2012 RDS桌面虚拟化之一VDI快速启动部署
- zju 3396 Conference Call
- ORA-28000: the account is locked-的解决办法
- Java线程池架构2-多线程调度器(ScheduledThreadPoolExecutor)