Search:
|
Browse by category:
|
| | | |
|
Question
How can I make a graphic object transparent, that is, control the alpha value or make it "see-through"?
Answer
Java provides support for alpha values in the java.awt.Color
class. This can be used to control the opacity of JViews graphics through their setForeground()
and setBackground()
methods.
Often you will want to control opacity for a group of graphics at one time. JViews provides a convenient method on its layers for this purpose: ilog.views.IlvManagerLayer.setAlpha(float)
. This sets the alpha value for all the objects on a layer (0.0 = invisible, 1.0 = solid).
Here is some code that sets the transparency level for a layer to 25%:
IlvManagerLayer layer = manager.getManagerLayer(1);
layer.setAlpha(0.75F);
manager.reDraw();
A sample application is available that demonstrates this.
Source code and scripts to build and run the application are provided in this file: seethru.zip.
Download and extract the file. Then read the HTML file it contains, seethru.html
.
Since JViews 8.1, you can encapsulate objects in IlvHalfZoomingGraphic
or IlvFullZoomingGraphic
. Both allow with an alpha parameter to make the encapsulated object individually transparent.
Prev | Next | |
Finding the best way to enforce the logic implied by Gantt Chart... | Making an interactor permanent |