JavaFX Tutorial 1 - Linear Gradient
The below example uses NetBeans release with JavaFX. Incase you have not installed NetBeans, please refer the link below
http://www.theasolutions.com/roller/javajee/entry/javafx_part_1_getting_started
Create a new JavaFX project [File--> New Project]. By default Main.fx file is created as the starting point of the application. Copy paste the below code into Main.fx.
/**
* @author karthikeyan c
*/
import javafx.application.*;
import javafx.scene.geometry.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import java.lang.System;
import javafx.scene.effect.light.*;
Frame {
stage:Stage {
content: [
Rectangle { x:0 y:0 width:1000 height:700 arcWidth:20 arcHeight:20
fill:LinearGradient {
startX:0 startY:0 endX:0 endY: 1
stops: [
Stop { offset:0 color:Color.web("#A1B8BF",1) },
Stop { offset:0.05 color:Color.rgb(0,0,0,1)},
Stop { offset:0.25 color:Color.web("#2E2A2A",1)},
Stop { offset:0.85 color:Color.web("#171715",1)},
Stop { offset:0.98 color:Color.web("#607980",1) },
Stop { offset:1 color:Color.web("#000000",1) },
]
}
}
]
}
visible: true
}
Note that visible:true is important.If we do not include it, the frame will not be visible.
You can also specify the color using RGB as below (instead of HEX value as in the above code)
Stop { offset:0.05 color:Color.rgb(0,0,0,1)},
The 1 at the end denotes the alpha value to be applied. Try to change the color values and also the offset it should start [which are 0,0.05,0.25,0.85,0.98 and 1 in the above code]
In the next tutorial let us place some input types on the stage.
Posted at 03:51AM Aug 09, 2008 by Karthik in JavaFX | Comments[0]


