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 942257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:14:38+00:00 2026-05-15T22:14:38+00:00

I have problem while setting the Jlabel location. I set the content pane to

  • 0

I have problem while setting the Jlabel location.

I set the content pane to some JPanel, I created and tried to add my JLabel.

    JLabel mainTitle = new JLabel("SomeApp");
    mainTitle.setFont(new Font("Arial",2 , 28));
    mainTitle.setBounds(0,0, 115, 130);
    getContentPane().add(mainTitle);

I want that my JPanel will be on the top left corner on my application and what I am getting is “SomeApp” on the top center.(and not top left).

btw I tried to add JButton the and the I can`t change the width,height,x,y of the JButton.

  • 1 1 Answer
  • 0 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-15T22:14:39+00:00Added an answer on May 15, 2026 at 10:14 pm

    Swing uses Layout Managers to place the components.

    You have to understand how they work to use them effectively. You can set the layout manager to null, and do the layout your self, but is not recommendable because you’ll have to keep track of new components each time, and perform layout computation your self when the window moves shrink etc.

    Layout managers are a bit hard to grasp at first.

    Your windows could be like this:

    as simple as this

    Using this code:

    import javax.swing.*;
    import java.awt.Font;
    import java.awt.FlowLayout;
    
    class JLabelLocation  {
    
        public static void main( String [] args ) {
    
            JLabel mainTitle = new JLabel("SomeApp");
            mainTitle.setFont(new Font("Arial",2 , 28));
            //mainTitle.setBounds(0,0, 115, 130); //let the layout do the work
    
            JFrame frame = new JFrame();
            JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));// places at the left
            panel.add( mainTitle );
    
            frame.add( panel );// no need to call getContentPane
            frame.pack();
            frame.setVisible( true );
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While I have the problem itself seemingly resolved, I'm hoping someone can shed some
I guess I have to set some context before I explain the problem I
The setting I have Backbone.Marionette.ItemView which renders some content. When the content is rendered
I have a problem while setting a private attribute on a PHP class, my
I have a problem while setting up my first Hibernate project. I follow the
I have encountered a problem while setting up the font properties file to train
I have problem while loading data into html select when users press or click
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code

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.