Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

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
0
tedschnieders
Asked:
tedschnieders
  • 3
  • 2
  • 2
  • +1
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now