Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java: JLabel for output

JavaFAQ Home » Swing, AWT Go to all tips in Swing, AWT


Bookmark and Share

Why using JLabel for output is usually bad

It'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.

  • Can't copy to clipboard. The user can not copy text from a JLabel, but can from a JTextField.
  • Can't set background. Changing the background of individual components probably isn't a good idea, so this restriction on JLabels is not serious. You can change the background of a JTextField, for better or worse.
  • Text length. This is where there are some serious issues. You can always see the entire text in a 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.

Changing the text of a JLabel

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);  // 

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy