Home > Java > Using ImageWidget, LabelWidget and LayerWidget in Visual Library API

Using ImageWidget, LabelWidget and LayerWidget in Visual Library API

Here is a basic Demo of how to use ImageWidget, LabelWidget, and LayerWidget in Visual Library API.
The LayerWidget is basically like JGlassPane in SWING. Here we first add a LabelWidget and ImageWidget to LayerWidget and then add that LayerWidget to the Scene object. Hope this will be useful as a basic simple example for anyone who wants to use these Widgets.

import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.netbeans.api.visual.widget.ImageWidget;
import org.netbeans.api.visual.widget.LabelWidget;
import org.netbeans.api.visual.widget.LayerWidget;
import org.netbeans.api.visual.widget.Scene;

 * @author Hassan Ali

public class VisualLibraryWidgets extends JFrame {

    //instance variables

    private Scene scene = new Scene();
    private JScrollPane pane = new JScrollPane();

    //class constructor

    public VisualLibraryWidgets() {

        this.setPreferredSize(new Dimension(400, 400));

        //add JScrollPane instance to JFrame instance


    //a method responsible for adding several widgets to the scene
    private void addWidgets() {

        //instantiate the LayerWidget, we would be adding other widgets
        //later in the code to this LayerWidget instance

        LayerWidget layer = new LayerWidget(this.scene);

        //instantiate the LabelWidget and add it to LayerWidget
        LabelWidget label = new LabelWidget(this.scene);
        label.setLabel("I am a LabelWidget!!");

        //instantiate the ImageWidget and add it to the Layer
        ImageWidget image = new ImageWidget(this.scene, new ImageIcon("C:/Documents and Settings/Administrator/Desktop/hello.jpg").getImage());
        image.setToolTipText("Hi! I am an ImageWidget!!");



    public static void main(String[] args) {

        VisualLibraryWidgets vlw = new VisualLibraryWidgets();


A LabelWidget and ImageWidget added to a LayerWidget in a Scene object

A LabelWidget and ImageWidget added to a LayerWidget in a Scene object

Categories: Java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: