First, double-click the JTextField
and JButton
to change
the default text that was inserted by the IDE. When you erase the text from the
JTextField
, it will shrink in size as shown below. Change the text of
the JButton
from "JButton1" to "Convert." Also change the top
JLabel
text to "Celsius" and the bottom to "Fahrenheit."
Setting the Component Text
Next, shift-click the JTextField
and JButton
components. This will
highlight each showing that they are selected. Right-click
(control-click for mac users) Same Size -> Same Width. The
components will now be the same width, as shown below. When you
perform this step, make sure that JFrame
itself is not also selected. If it is, the Same Size menu will not be active.
Setting the JTextField and JButton Sizes
JFrame
and adjust its size to
eliminate any extra whitespace. Note that if you eliminate all of the extra space (as shown below)
the title (which only appears at runtime) may not show completely. The end-user is free to resize
the application as desired, but you may want to leave some extra space on the right side
to make sure that everything fits correctly. Experiment, and use the screenshot of the finished GUI
as a guide.
The Completed GUI
To see the code in its entirety, scroll up and down within the IDE as necessary. You can expand or collapse certain blocks of code (such as method bodies) by clicking the + or - symbol on the left-hand side of the source editor.