Page 753 - Introduction to Programming with Java: A Problem Solving Approach
P. 753

                17.11 JtextArea Component 719 logarithm value. Specifically, the %7.5f conversion specifier returns a floating-point value with 5 decimal
places and 7 total characters.
17.11 JtextArea Component
In the previous chapter, we introduced you to a few GUI components—JLabel, JTextField, JButton, and JOptionPane—that provide basic input/output functionality. Now we’ll introduce you to a few more GUI components—JTextArea, JCheckBox, JRadioButton, and JComboBox—that provide more advanced input/output functionality. We’ll start with the JTextArea component.
User Interface
The JLabel component works great for displaying a single line of text. As described in Chapter 16, you can use a JLabel component to display multiple lines of text, but achieving multiple lines requires clutter- ing up your code with HTML <br> line-break tags. The preferred technique for displaying multiple lines of text is to use a JTextArea component. The large white area in Figure 17.10 is a JTextArea compo- nent. By the way, the small shaded area at the bottom of Figure 17.10 is a JCheckBox component. We’ll describe JCheckBox components in the next section.
Figure 17.10 A window with a JTextArea component and a JCheckBox component
Implementation
To create a JTextArea component, call the JTextArea constructor like this: JTextArea <JTextArea-reference> = new JTextArea(<display-text>);
The display-text is the text that appears in the JTextArea component. If the display-text argument is omitted, then the JTextArea component displays nothing.
Methods
The JTextArea class, like all the GUI component classes, has quite a few methods. Here are the API headings and descriptions for the more popular JTextArea methods:
public String getText()
  Apago PDF Enhancer
⎫
⎪⎬⎪⎭
   JTextArea
component
    ⎫⎬⎭
JCheckBox
component
  Returns the text area’s text.













































































   751   752   753   754   755