JLabel
for output is usually badIt's possible to change the text of a JLabel, although this is
not generally a good idea after the user interface is already displayed.
For output JTextField
is often a better choice.
The use of JLabel
for output is mentioned because some textbooks
display output this way.
Here are some reasons not to use it.
JLabel
, but can from a JTextField
.
JLabels
is not serious. You can change the
background of a JTextField
, for better or worse.
JTextField
, altho you might have to
scroll it it's long. There are several possibilities with
a JLabel
. You may either not see all of the
long text in a JLabel
, or putting long text
into a JLabel
may cause the layout to be
recomputed, resulting in a truly weird user experience.
Most JLabels are never changed, except for internationalization, and that is done before the user interface is shown. To change the text, use
yourLabel.setText(String newText); //