![]() |
![]() |
![]() |
![]() |
Assemble the GUI
You will now begin to assemble the graphical components for your Text Editor. All of the graphical components can be found in the Object Palette window.
All graphical components in a Java application are placed into Java Layouts. The Layouts position your components so that they will be properly sized to be attractive regardless of the operating system that your application is running on. While most of the layouts are rather simple, they can be combined to create just about any component placement you desire.
We will start by using a Border Layout. A Border Layout can hold up to five components, located in the North, South, East, West, and Center. The layout tries to give the four border components their 'preferred' size, and any space left over goes to the Center component.
- On the Object Palette, make sure that the first page, 'Layouts', is visible. (If not, click the mouse button on the 'Layouts' Tab.)
- You will see icons for all of the available layouts. Click the first icon, named 'Border', with the mouse. (It should now appear depressed. Also, the title bar of the Object Palette will reflect your selection.)
- In the program window, click once in the center. You have just placed a Border Layout into the window. You should now see five empty spaces, labeled North, South, East, West, and Center. Each of these spaces can hold a component (or another layout).
- On the Object Palette select the second page's tab, labelled 'Basic'. This page contains all of the basic components which are part of the Java library.
- Click the second to last icon, named TextArea. It should appear depressed.
A TextArea is a component which can hold multiple lines of text, and is optionally editable and scrollable.- Click the mouse once in the 'Center' empty space in the Border Layout which you previously placed in the main window. This will put a TextArea in the center of the Border Layout.
- In the composer window, you will see the properties notebook for the TextArea that you just created. Edit its properties by settings 'Rows' to 5 and 'Columns' to 40. Make sure that 'Editable' is selected, and erase any text in 'TextArea text'.
- Each component is given a name which you use to refer to each component when you write Java code. In the properties for the TextArea you'll see that the current 'Object name' is set to 'textArea2'. Change it to a simpler, more descriptive name, 'text'.
- On the Object Palette, choose the 'Layouts' page and click the second icon, named Flow. Click once in the 'North' empty space of the Border Layout that you previously put in the window. You have just put a new Flow Layout in the northern part of your Border Layout.
A Flow Layout lays out components in a row and wraps to a new line if more space is needed. You see a single empty space where you can place components. As you click components into this space, the space moves to the right.- On the Object Palette, choose the 'Basic' page and click the fourth icon, named Button. Click once in the empty space inside the Flow Layout you just created. A new button appears and the empty space moves to the right. Click again in the flow's empty space to add another button. Do this one more time to add a third button.
- To be careful, save your work by pressing the 'Save' button at the top of the Composer window (the red disk icon).
If by accident you placed a part in the wrong empty space, you can remove it by using the 'Recycle' button. Choose the part by clicking it with the mouse button. Then push the 'Recycle Current Part' button located toward the top of the Composer window. The part will be removed from your program and will appear as an icon in the 'Recycled' page in the Object palette. You can select it from the palette if you wish to reuse it elsewhere. If you recycle a layout, the entire contents of the layout are moved to the Recycle page.
Data Representations, Inc. http://www.datarepresentations.com support@datarepresentations.com sales@datarepresentations.com |
![]() |
![]() |
![]() |
![]() |