Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
JTextAreas and JPasswordFields
-
JPasswordField
-
A JPasswordField is much like a JTextField, but it echos an '*'
instead of the text the user typed.
-
You can change the echo character in the constructor.
-
For better security, it has a getPassword() field that returns a character
array.
-
JTextArea
-
With the JTextArea, you can use a constructor to specify the number of
columns and rows.
-
Example: JTextArea txtEssay = new JTextArea(4, 30); will make
a JTextArea of 4 rows and 30 columns.
-
By default, text that goes beyond the JTextArea component is clipped,
or scrolled out of view. You can wrap long lines by using the
TextArea method setLineWrap(boolean b);
-
Of course, you could give the user this option by having a button that
calls this method on the JTextArea object on the button listener's actionPerformed(ActionEvent
e) method.
-
But, if you want scroll bars, you must add the text area to a JScrollPane
object. Do that like so:
JTextArea txtEssay = new JTextArea(4, 30)
JScrollPane scrEssay = new JScrollPane(txtEssay);
pnlEntry.add(scrEssay);
-
Note that you add the JTextArea object to the JScrollPane, and then the
JScrollPane to the container (JPanel or JFrame). You do not add the
JTextArea object directly to the JScrollPane object. Or, again, just
let Forte' do it all for you.
JLabel



Created by: Brandan
Jones January 4, 2002