A simple demonstration of text alignment in JLabels : Label « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » LabelScreenshots 
A simple demonstration of text alignment in JLabels
A simple demonstration of text alignment in JLabels

//A simple demonstration of text alignment in JLabels.

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class AlignmentExample {
  public static void main(String[] args) {
    JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT);
    JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER);
    label1.setVerticalAlignment(SwingConstants.BOTTOM);
    label2.setVerticalAlignment(SwingConstants.CENTER);
    label3.setVerticalAlignment(SwingConstants.TOP);

    label1.setBorder(BorderFactory.createLineBorder(Color.black));
    label2.setBorder(BorderFactory.createLineBorder(Color.black));
    label3.setBorder(BorderFactory.createLineBorder(Color.black));

    JFrame frame = new JFrame("AlignmentExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new GridLayout(3188));
    p.add(label1);
    p.add(label2);
    p.add(label3);
    p.setBorder(BorderFactory.createEmptyBorder(8888));
    frame.setContentPane(p);
    frame.setSize(200200);
    frame.setVisible(true);
  }
}

           
       
Related examples in the same category
1. Putting HTML text on Swing componentsPutting HTML text on Swing components
2. Shows how displayed Mnemonic and labelFor properties work togetherShows how displayed Mnemonic and labelFor properties work together
3. A quick application to show a simple JLabelA quick application to show a simple JLabel
4. A JLabel that uses inline HTML to format its textA JLabel that uses inline HTML to format its text
5. Variations on a text and icon labelVariations on a text and icon label
6. Label with Image Label with Image
7. Label with HTML SampleLabel with HTML Sample
8. Label Text PositionLabel Text Position
9. LabelFor DemoLabelFor Demo
10. Label with IconLabel with Icon
11. Active Label SampleActive Label Sample
12. Swing Label DemoSwing Label Demo
13. Label alignmentLabel alignment
14. HTML labelHTML label
15. Label background, icon, alignLabel background, icon, align
16. Scrollable LabelScrollable Label
17. Grab and Drag image scroll labelGrab and Drag image scroll label
18. Animation label
19. Label with various effectsLabel with various effects
20. Label for Label for
21. LabelFocusSample: setLabelForLabelFocusSample: setLabelFor
w_w_w.__j__a___v___a___2_s___._c_om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.