Changing the icon of a node

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.

  1. Using one of the provided icons in JBotSim
  2. Using your own icon

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).

Using one of the provided icons

import io.jbotsim.core.Node;
import io.jbotsim.ui.icons.Icons;

public class MyNode extends Node{
    public MyNode(){

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.

Using your own icon

Your icon should preferably:

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.




depending on where you placed it.