Finding Matisse
Code named "Matisse", the NetBeans GUI (Graphical User Interface) builder is a little known but marvelous tool for developing user interfaces in Java. It has been included in NetBeans since version 5.0 but it is developing rapidly and you might start by installing NetBeans 6.0.
It is not obvious how to invoke Matisse so I will provide a step by step "howto" .
- Bring up NetBeans IDE (if you have installed it you should find it in Start, All Programs. I add the NetBeans desktop icon to my panel in Linux)
- Right click Project, then New Project
- Choose Java (General in previous versions), Java Application, Next
- Name your application (the default names get might confusing after while. Tradition has yoour first program named HelloWorld)
- Unset "Create Main Class" and click Finish. The first time a lot of "indexing" goes on - be patient.
- Right click "Source Packages" and "New", JFrame Form
- Name the frame and click Finish
- Double click on your frame and notice the "Design" tab - that's Matisse
- Open Swing Menus (this stuff is different on earlier versions) and drag a Menu Bar onto the big gray box in the middle
- Two Menus "File" and "Edit" are automatically created. In older versions you had to drag a Menu Item onto the Menu. Right click on File and Insert a MenuItem. Change the "Text" to something like "Hello".
- Select the Item you created and Click Events, Action, ActioPerformed. Matisse will create an actionPerformed stanza in your code ready for you to do something.
- Find the comment TODO add your handlling code here.
- Type System.out.println("Hello World");
- Press F6. In the Run Project window, you will see your frame has been proposed as your main class. Click OK
- After a few seconds (it will get faster next time), NetBeans will compile and run your application.
- Click File, then Hello.
- Now look in the Output Window and you will see "Hello World"
Congratulations, you have created a program with a Menu Bar that does something.
Clearly, you will want to design your menu and name the objects appropriately so that you can find your way through the forest. Go back to Design, Choose the Inspector (if he ever disappears, you can bring him back in the NetBeans Menu - Window, Navigating, Inspector). Right click on an object and choose Change Variable Name). With a little practice you can choose names which help you keep track of everything.
Change the text of your menus and menu items by choosing each object and then scrolling down to "Text" in the Properties Window and changing the value box next to it with the stuff you want.
We have examined only a tiny fraction of the capabilities of NetBeans but the key to success is staying on the "bunny slope", doing one thing at a time and testing your work frequently (you can't do it too often) by pressing F6.
Thanks Henri.
