Published August 22nd, 2008
Gradient in Java FX - Shading and 3D effect !
One thing that makes life very easy in JavaFX is the effect of Gradient. There are two types of Gradient support in JavaFX - Linear and Radial.
Linear Gradient is good for shading like

So, you can see the gradient of Black and Red on ball. Why 2 circle because in this code, I want to show you how to achieve same effect from proportional coordinate and from absolute coordinate :-). Here is the code:
package gradientexample;
import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.geometry.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.paint.*;
import javafx.scene.geometry.Circle;
Frame {
title: "MyApplication"
width: 500
height: 500
closeAction: function() { java.lang.System.exit( 0 );
}
visible: true
stage: Stage {
content: [
Circle {
centerX: 100, centerY: 100
radius: 40
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 1.0
endY: 0.0
proportional: true
stops: [
Stop { offset: 0.0 color: Color.BLACK },
Stop { offset: 1.0 color: Color.RED }
]
}
},
Circle {
centerX: 200, centerY: 200
radius: 40
fill: LinearGradient {
startX: 160.0
startY: 0.0
endX: 240.0
endY: 0.0
proportional: false
stops: [
Stop { offset: 0.0 color: Color.BLACK },
Stop { offset: 1.0 color: Color.RED }
]
}
}
]
}
}
Now, Have a look of Radial Gradient, this can be used to generate 3D effect on a ball like : 
Here is the code for 3D ball generator. Just click on the button on the top and it will keep on generating the random color, select the good for your application and just put it
Here goes the code:
package gradientexample;
import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.geometry.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.paint.*;
import javafx.scene.geometry.Circle;
import javafx.ext.swing.Button;
import java.util.Random;
import javafx.ext.swing.ComponentView;
import javafx.scene.effect.*;
var color: Color = Color.RED;
var rnd : Random = new Random();
var button = Button {
text: "3D Ball Generator"
action: function() {
color = Color.rgb(rnd.nextInt(255),rnd.nextInt(255),rnd.nextInt(255))
}
}
Frame {
title: "3D Ball Generator"
width: 700
height: 700
closeAction: function() { java.lang.System.exit( 0 );
}
visible: true
stage: Stage {
fill: Color.GRAY
content: [
Circle {
centerX: 200, centerY: 200
radius: 70
fill: bind RadialGradient {
centerX: 170
centerY: 170
radius: 100
proportional: false
stops: [
Stop { offset: 0.0 color: Color.WHITE },
Stop { offset: 1.0 color: color },
]
}
effect: GaussianBlur {
radius: 70
input: Flood {
paint: Color.BLACK
}
}
opacity: 0.6
},
ComponentView {
component: button
}
]
}
}
Lot of good examples on these gradient are available on net.











Java,JavaScript,Threading,
Optimization and more with Vaibhav 


