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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:02:23+00:00 2026-06-05T03:02:23+00:00

my problem is, that when I create a JButton, whithin its constructor, I set

  • 0

my problem is, that when I create a JButton, whithin its constructor, I set its location to some relative coordinates, say x = 5, and y = 6, using the following code:

this.setLocation(new Point(x, y));

but after I am trying to get its location using the getLocation() method, it always returns 0,0. Please note that this happens for every JButton I am trying to place on a grid layout powered JFrame, and during the debugging process, I have also noted that their location is being properly instantiated.

Can someone explain to me why this happens, and if I can fix it somehow?

EDIT:

The constructor (The brick class that I made, extends JButton):

public Brick(int posx, int posy) {
        this.setLocation(new Point(posx, posy));
        this.setVisible(true);
    }

I make about 100+ of them in 2 for loops:

   for (int row = 0; row < 15; row++) {
    for (int column = 0; column < 15; column++) {
    Brick brickie = new Brick(row, column);
    }
   }

But afterwards, if I wanna pick a brick and check its location like this:

Point brickLocation = brickie.getLocation();

both brickLocation.x == 0 and brickLocation.y == 0

  • 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-05T03:02:25+00:00Added an answer on June 5, 2026 at 3:02 am

    You are trying to change button location when it is automatically assigned by layout manager (your GridLayout). That is why you are always getting the same value back – layout just overwrites it.

    To be able to change any component bounds/location (including buttons) manually – you have to set “null” as the container’s layout. After that just change the location/size/bounds as you like and it will affect the components positions.

    Also you don’t need to use “setVisible(true)” – by default that flag is true for all components (even those that aren’t displayed yet).

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

Sidebar

Related Questions

I am using EASYGRAPH for to create graph in iphone app problem is that
I want to create a crawler with C#. The problem is that some websites
i am using visual studio2010. i am facing a problem that when i create
the problem that im having is this that i am able to create a
I want to create a natural flow of content. The problem that I now
I know how to create one to one relationship only problem is that it
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
Problem I want to create an application that can be extended somehow by programmers.
The problem: To create a recursive array function that walks through a three dimensional
The problem I'm having is that when I try to create a table via

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.