Some JComponent Manipulation | |
JTextField
balj |
JComponents | |
The basic GUI widget are represented by subclasses of JComponent.
The Java Swing Trail provides a handy
Visual Index to Swing Components
The basic procudure to add a JComponent to a pane, is to instantiate it and then add it to the ContentPane of the container that you want to add it to: JButton button = new JButton("Click Me!"); this.getContentPane().add(button); The basic JComponents:
|
Layout Managers | |
Layout managers determine who components are laid out inside of a container. Again, the
Java Swing Tutorial provides a
Visual Guide
To use a Layout manager, we use the setLayout method on the Pane we want to control: this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));This example well tell the JFrame to layout the components in vertical line, by default, centered. This is generally done before adding components. Note that with most layout managers, the order in which you add components effect how they are placed into the container. The basic LayoutManagers that you should get the hang of:
|
Exercise |
|
Create a dummy GUI as shown in this screenshot:
Hint: This can be done by combining about six JPanels using BoxLayout, consider using GridLayout. While many IDE provide GUI builders which are very helpful, and you are encouraged to use them in general. Do this exercise by hand, even with a good GUI builder, you need to be able to understand what it's doing.
For Monday, Due Wednesday 5PM |