Trace: » output » threads » plugins » cookies » userdir » xml_layer » dataobject » fileobject » serial_java » gui_building
GUI building
NetBeans provides a nice GUI maker called Matisse Matisse comes with a palette of components, to which you can add your own
Layouts
Containers allow you to select their Layout (Rclick/Set Layout)
Free Layout
This Layout makes things pretty for you by lining them up etc. It can be restrictive.
Null Layout
When you select this layout, all your buttons etc will crunch to the uppermost corner. you can move them back out, of course. this layout allows you much more freedom (but do you want it?). use it if you're designing a window that you want to add to another, enclosing component with a box layout.
Box Layout
you can use this layout if you want the container to look like a matrix. As soon as you select it, the Inspector will show it. You can add components to a box layout like an array. You don't have to specify ahead of time the # of rows or columns. (set these properties to 0 from GridLayout/Properties in the Inspector) If you want to keep adding more rows/columns (eg by allowing the user to add more buttons), make sure the button design (if it's a container itself with lots of related buttons) has a null layout. if it doesn't, then the components won't be resized to fit in the screen as you add more. they just run off the screen.
.Form files
When you make a new GUI component, there are two files, name.java and name.form created in the folder. one of them, however, is invisible from the Projects dialog
Why can't i see the .form files? according to NetBeans Wiki: DevFaqDataObject it is because the .java and .form files are jointly represented with a single DataObject. Because the DataObjects are the ones which can be displayed, only one files is visible in the UI.
Uneditable Code
When you make a new graphical component with Matisse, all the numbers that specify how it should look (there are a lot of numbers) are inserted into a code fold in the source code called “Generated Code”. If you expanded, you can see that this code implements the method InitComponents(), which is called in the constructor. You shouldn't have to modify this code, and you probably don't want to. This code contains the action listeners.
However, you may find yourself wanting to modify it for various reasons. You could copy the code to a new java class and change it there. Unfortunately, copying means you can't look at the GUI as you're building it any more, because, as far as the NetBeans IDE is concerned, it's not really a GUI any more because it's missing the “form” file (the one which the Inspector inspects). This means that you have to either figure out how to write the form file or give up the ability to change your form with matisse. You probably don't want to do this.
It is better to add your own intialization method which runs after InitComponents() in the constructor and makes all the changes you want. Sometimes you make a lot of little customizations for a button. You add an icon, set the font, define an action listener through matisse etc, set the title etc. If you then realize that you'd rather implement that functionality with another kind of button, you have to change all those things again. Also, let's say you want to see how your GUI looks without a button. You could temporarily remove it and add it back if you find it necessary. If you want to do these kinds of things, you can use virtual buttons. Let's say you want a “clean the dog” button. You can write a function called “get_clean_the_dog_button” which returns something like jbutton3; You can then set all the properties of that button in your own initialization function, but leave the InitComponents() function to do the dirty positioning work. If you ever want jbutton4 to become the clean_the_dog button, you have to change only one function.