Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 701189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:34:55+00:00 2026-05-14T03:34:55+00:00

At the moment I have the following code which works fine. label = new

  • 0

At the moment I have the following code which works fine.

label = new JLabel(panelLabel,SwingConstants.CENTER);
outputPanel.add(label,BorderLayout.CENTER);

I get the text in the center of the panel (in terms of the left-right position as well as in terms of the top-bottom).

Now I want to set the position to the bottom (and center in terms of “left-right”). I tried to use SOUTH instead of the CENTER in the first line. Compiler does not complains but during the execution i get IllegalArgumentException: HorizontalAlignment. What is that?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:34:55+00:00Added an answer on May 14, 2026 at 3:34 am

    The JLabel constructor you are using is JLabel(String label, int horizontalAlignement).

    As defined in the javadoc, this int should be only in certain values:

    JLabel public JLabel(String text, int horizontalAlignment)
    Creates a JLabel instance with the
    specified text and horizontal
    alignment. The label is centered
    vertically in its display area.

    Parameters:
    text – The text to be displayed by the label.
    horizontalAlignment – One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.

    This value sets where your text is aligned, inside the JLabel. You can’t use “SOUTH” here, and this is why you get the “InvalidArgument” exception.


    If you want to make your text on the bottom of the label, you have to use setVerticalAlignment(int), with Swingconstants.BOTTOM. That supposes that your label is centered and will potentially take a wide height on your panel.

    If you use a BorderLayout for this panel, you might want to try to add your label with BorderLayout.SOUTH, as hint for the layout manager. This will stick the label to the bottom part, and it will have a minimal height (the one necessary to display the text). In this case, the vertical alignment of the text doesn’t really matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code which walks through an Excel file and this works
I have the following code: http://jsfiddle.net/uRCL2/1 At the moment the result is shown in
The following code summarizes the problem I have at the moment. My current execution
I have a form that submits through Ajax, which works perfectly at the moment.
I have the following code, which groups some events (YYYY-MM-DD HH:MM:SS) in weeks which
At the moment, I have the following code: Public tmr() As DispatcherTimer Public Sub
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
Okay, at the moment I have the following in my model: has_many :current_monitorings, :class_name
Got a bit of a mind freeze at the moment. I have the following
I just started using django for development. At the moment, I have the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.