JLabel : JLabel « Swing « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Swing » JLabel 
14. 3. 1. JLabel
  1. A JLabel represents a label, i.e. a display area for non-editable text.
  2. A JLabel can display both text and images.
  3. It can even render HTML tags so that you can create a JLabel that displays multicolors or multiline text.

The javax.swing.JLabel class has the following constructors.

public JLabel ()
public JLabel (java.lang.String text)
public JLabel (java.lang.String text, int horizontalAlignment)
public JLabel (Icon image)
public JLabel (Icon image, int horizontalAlignment)
public JLabel (Java.lang.String text, Icon icon, int horizontalAlignment)

The value of horizontalAlignment is one of the following:

  1. SwingConstants.LEFT
  2. SwingConstants.CENTER
  3. SwingConstants.RIGHT
  4. SwingConstants.LEADING
  5. SwingConstants.TRAILING

If you want to use multifonts or multicolors in a JLabel, you can pass HTML tags,

A JLabel subclass is used as the default renderer for each of the JList, JComboBox, JTable, and JTree components.

Alignments have an effect only if there's extra space for the layout manager to position the component.

14. 3. JLabel
14. 3. 1. JLabel
14. 3. 2. Create JLabel component
14. 3. 3. Create a JLabel with an image icon
14. 3. 4. JLabel is for displaying text, images or both. It does not react to input events.
14. 3. 5. Horizontal Alignment: CENTER
14. 3. 6. Vertical Alignment: CENTER
14. 3. 7. Horizontal Alignment: LEFT
14. 3. 8. Vertical Alignment: TOP
14. 3. 9. Horizontal Alignment: RIGHT
14. 3. 10. Vertical Alignment: BOTTOM
14. 3. 11. The text is horizontally and vertically centered
14. 3. 12. The text is right-justified and vertically centered
14. 3. 13. The text is left-justified and top-aligned
14. 3. 14. The text is right-justified and top-aligned
14. 3. 15. The text is left-justified and bottom-aligned
14. 3. 16. The text is right-justified and bottom-aligned
14. 3. 17. Add Icon to JLabelAdd Icon to JLabel
14. 3. 18. Mix Icon and text in JLabelMix Icon and text in JLabel
14. 3. 19. Set Font and foreground color for a JLabelSet Font and foreground color for a JLabel
14. 3. 20. Load image from disk file and add it to a JLabelLoad image from disk file and add it to a JLabel
14. 3. 21. Using JLabel Mnemonics: Interconnect a specific JLabel and JTextField.Using JLabel Mnemonics: Interconnect a specific JLabel and JTextField.
14. 3. 22. Using a JLabel and pass in HTML for the textUsing a JLabel and pass in HTML for the text
14. 3. 23. Multiline label (HTML)
14. 3. 24. JLabel with more than one row
14. 3. 25. A simple Bean which extends JLabel
14. 3. 26. Add JLabel to JScrollPane
14. 3. 27. Disable a label
14. 3. 28. Unicode with Label
14. 3. 29. Customizing a JLabel Look and Feel
14. 3. 30. Associate JLabel component with a JTextField
14. 3. 31. Setting the Focus of a JTextField Component Using a JLabel Component
14. 3. 32. JLabel with lined border
14. 3. 33. A Label that uses inline HTML to format its text
14. 3. 34. A label with no indication it has been clicked
14. 3. 35. Adding Drag-and-Drop Support to a JLabel Component
14. 3. 36. Have a Label with underlined text
14. 3. 37. Multi Line Label
14. 3. 38. Vertical Label UI
14. 3. 39. Time panel shows the current time.
14. 3. 40. URL Label
14. 3. 41. Hyperlink Label
14. 3. 42. Gradient Label
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.