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

  • SEARCH
  • Home
  • 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 8541833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:55:13+00:00 2026-06-11T11:55:13+00:00

How do I move a component in a frame while I am using a

  • 0

How do I move a component in a frame while I am using a layout? I have tried this:

    System.out.println(test1.getLocation());
    int oy = test1.getY();
    int ox = test1.getX();
    oy++;
    ox++;
    test1.setLocation(ox, oy);
    validate();
    test1.validate();
    System.out.println(test1.getLocation());

The first location is the same as the last location. I know that you can’t change the location while in the layout normally, but how do you accomplish it? I have asked a similar question before and never got an answer. I have searched all over the internet for this, but I haven’t found an answer.

TL;DR – How do you move a component?

  • 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-06-11T11:55:14+00:00Added an answer on June 11, 2026 at 11:55 am

    The problem is that the LayoutManager of the panel is setting the location of the label for you.

    What you need to do is set the layout to null by:

    setLayout(null);
    

    This will make it so the frame/panel doesn’t try to layout the components by itself.

    Then call setBounds(Rectangle rect) on the label. Like so:

    lbl.setBounds(new Rectangle(new Point(200, 300), lbl.getPreferedSize()));
    This should place the component where you want it.

    However, if you don’t have a really great reason to lay out the components by yourself, it is usually a better idea to use LayoutManagers to work in your favour.

    Here is a great tutorial on getting started with using LayoutManagers, if though you must use absolute then have a look at this tutorial

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

Sidebar

Related Questions

I have put a label into my frame, but it refuses to move. SetBounds()
I have a TFrame with a TImage as background. This frame serves as ancestor
I am trying to move some files in python, but they have spaces in
I would like to move a circle along a circular path using HTML/CSS/JavaScript. Is
I have a system in place for a game yet I don't know what
So I have that panel or any other mxml component. I want somehow to
is it possible to move a flex mxml project into flash? i have the
This is my JFrame code: public static int width = 800; public static int
I'm changing the parent of a frame a runtime to move the frame from
I have a flex component with 2 states - (ie no name / default)

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.