Making a graphic object transparent, that is, control the alpha value or make it "see-through"

Article ID: 2216
Last updated: 29 May, 2018
Article ID: 2216
Last updated: 29 May, 2018
Revision: 3
Views: 515
Posted: 23 Jun, 2010
by Dean J.
Updated: 29 May, 2018
by Gargani A.

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.

Transparent objects

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.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2216
Last updated: 29 May, 2018
Revision: 3
Views: 515
Posted: 23 Jun, 2010 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category