Subclassing IlvGeneralNode to add CSS parameters and change the node shape

Article ID: 2250
Last updated: 29 May, 2018
Article ID: 2250
Last updated: 29 May, 2018
Revision: 3
Views: 561
Posted: 01 Mar, 2011
by Dean J.
Updated: 29 May, 2018
by Gargani A.


How to subclass IlvGeneralNode to add CSS parameters and change the node shape?


This sample shows an SDM graph with two nodes and a link. The shape of each node is set to an IlvGraphicSet containing an IlvLabel on top and an IlvIcon below. This is done using MyNode, a subclass of IlvGeneralNode. The fields for the text and the icon are set through the CSS file.

Note that an icon file has to have 24-bit color depth in order for Java to know which colors to use.

To run the sample, unzip the file, then compile "" and "", and finally run "Main".

import ilog.views.sdm.graphic.*;
import ilog.views.graphic.*;
import ilog.views.*;
import java.awt.*;
public class MyNode extends IlvGeneralNode {
private String iconKey;
private String textKey;
public void setIconKey(String inIconKey)
iconKey = inIconKey;
if(textKey != null)
public void setTextKey(String inTextKey)
textKey = inTextKey;
if(iconKey != null)
private void mySetShape()
IlvGraphicSet graphicSet = new IlvGraphicSet();
new IlvIcon(iconKey, new IlvRect(0, 0, 32, 32)), false);
new IlvLabel(new IlvPoint(16, -8), textKey), false);

import ilog.views.*;
import ilog.views.interactor.*;
import ilog.views.sdm.*;
import ilog.views.swing.*;
import javax.swing.*;
public class Main
public static void main(String args[]) throws IOException, IlvSDMException
// Create a window
JFrame window = new JFrame("Main");
window.setBounds(20, 20, 400, 300);
// Add an SDM engine with a select interactor to the window
IlvSDMEngine engine = new IlvSDMEngine();
IlvManagerView view = new IlvManagerView(engine.getGrapher());
view.setInteractor(new IlvSelectInteractor());
window.getContentPane().add(new IlvJScrollManagerView(view));
// Load the style sheet and the XML file
engine.setStyleSheets(new String[] { "file:simple.css" });
// Show the window;


node {
class : MyNode;
iconKey : "icon.png";
textKey : @label;
link {
class : ilog.views.sdm.graphic.IlvGeneralLink;
lineWidth : 4;
minimumLineWidth : 2;
maximumLineWidth : 8;
oriented : true;
foreground : "blue";


<?xml version="1.0" encoding="UTF-8"?>
<node id="node1">
<property name="label">Node 1</property>
<property name="x">50</property>
<property name="y">50</property>
<node id="node2">
<property name="label">Node 2</property>
<property name="x">150</property>
<property name="y">50</property>
<link islink="true" id="link1" from="node1" to="node2">
<property name="type">IN</property>

Note: In order to run this sample with JViews 8.7 and later, you must call the ilog.views.util.IlvProductUtil.DeploymentLicenseRequired method with the appropriate argument. See the General information > Deployment licenses > Declaring the use of IBM ILOG JViews services section in the documentation for more information.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2250
Last updated: 29 May, 2018
Revision: 3
Views: 561
Posted: 01 Mar, 2011 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Attached files

Others in this category