adding JLabel right justified

I am adding a JLabel to a  container with a border layout and i need to know how to make it right justified or where i would look at java.sun.com to find the answer.


thanks much
Ted Schnieders
tedschniedersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
You can also specify alignment in JLabel constructor
0
suprapto45Commented:
Hi Ted Schnieders,

Do you want it to be right justified in the label itself or do you want it to be right justified in the BorderLayout?

Regard
Dave
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JavatmCommented:
You can do it like this :

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * @author Javatm
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Sample extends JFrame {

      public Sample() {
            
            super("Sample . . .");
            
            JLabel label1 = new JLabel();
            label1.setText("Right Side");
            
            getContentPane().add(label1, BorderLayout.EAST);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(400, 300);
            setVisible(true);
      }
      public static void main(String[] args) {
            Sample x = new Sample();
      }
}
0
Mayank SAssociate Director - Product EngineeringCommented:
This describes how to use JLabels - http://java.sun.com/docs/books/tutorial/uiswing/components/label.html

Choose whichever way you want.

BTW, Javatm, welcome back :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
There's also a sample here which does lots of alignment and stuff: http://www.java2s.com/ExampleCode/Swing-JFC/Labelalignment.htm
0
JavatmCommented:
> BTW, Javatm, welcome back :)

Yap, I was prett busy w/ my new work, kind super bc this past few months. I can see that your already a wizard.
May the force be w/ you I'll try to notch few more points for that, thanks.
0
Mayank SAssociate Director - Product EngineeringCommented:
Good luck :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.