By default, the nodes are represented by a circle. You can change the icon of a node by using the setIcon()
method, in two possible ways.
It is also possible to change the size of a node by calling setIconSize()
, this method having only a graphical impact (it does not affect the underlying simulation).
import io.jbotsim.core.Node;
import io.jbotsim.ui.icons.Icons;
public class MyNode extends Node{
public MyNode(){
setIcon(Icons.ROBOT);
setIconSize(16);
}
}
Here, the setIcon()
method is called from the constructor. It is also common to do this from the onStart()
method. (More generally, you can do it at any time.) The list of available icons is here.
Your icon should preferably:
Node.setDirection()
is used)For instance, this image meets the requirements.
Once your image is ready, place it within your project in a resource directory or along your source code. The argument of the setIcon()
should be your icon path within the project, e.g.
setIcon("/myicon.png");
or
setIcon("/mypackage/myicon.png");
depending on where you placed it.