Archive

Archive for January, 2011

Creating Scene and using a simple LabelWidget in NetBeans Visual Library

January 7, 2011 Leave a comment

A simple Demo for Creating a Scene and adding a LabelWidget instance to it in NetBeans Visual Library API

package visuallibrary;

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

/**
 *
 * @author Hassan Ali
 */
public class Main extends JFrame {

    /**
     * A basic Demo about creating scenes and a basic LabelWidget in
     * NetBeans Visual Library
     */

    //instance attributes


    //create a Scene instance
    private Scene scene = new Scene();

    //create a LabelWidget instance
    private LabelWidget widget = new LabelWidget(scene, "I am a LabelWidget");


    //class cosntructor
    public Main() {

        scene.addChild(widget);                  //add the LabelWidget instance as a child of the Scene object

        setMinimumSize(new Dimension(500, 500));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //instantiate a JScrollPane
        JScrollPane pane = new JScrollPane(scene.createView());   //scene.createView creates a scene that is JComponent
                                                                  //and could be used likely
        add(pane);                      //add JScrollPane instance to the JFrame instance
        setVisible(true);
    }

    public static void main(String[] args) {
        // TODO code application logic here
        Main m = new Main();
    }

}
Advertisements
Categories: Java