Solved

Label text allignment

Posted on 2004-10-23
196 Views
Last Modified: 2010-03-31
Hi Experts!!
Here is a piece of code i am using to postion the text in my label in center, but it not working. Could u please tell me what is wrong?

================Code=========================
aDie = new JLabel( String.valueOf(top)  );
      aDie.setLayout(null);
       aDie.setAlignmentX(CENTER_ALIGNMENT);
      aDie.setBounds(10, 10, 10, 10);
      aDie.setPreferredSize(new Dimension(90,90));
     aDie.setFont(new Font("Sansserif", Font.BOLD, 80));
   

     aDie.setOpaque(true);
     aDie.setBackground( Color.white );
   
0
Question by:komlaaa
    3 Comments
     
    LVL 86

    Accepted Solution

    by:
    JLabel aDie = new JLabel(String.valueOf(top), SwingConstants.CENTER);
    0
     

    Author Comment

    by:komlaaa
    Thanks CEHJ, the answer was quick!!
    thanks again.
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    8-)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Title # Comments Views Activity
    map interface methods 3 35
    java ^ examples 8 40
    triangle challenge 4 19
    strCount chalenge 3 19
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now