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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:43:13+00:00 2026-06-05T00:43:13+00:00

I have searched for this problem and haven’t found anything close. I will try

  • 0

I have searched for this problem and haven’t found anything close. I will try to be specific and post code however this is a large program so I can’t post all the code. The problem in general is this: A JButton on one panel causes components on another panel to shift at first click. This only occurs when there is an action listener added to the button. (clicking the button without an action listener doe noting (obviously)). The problem is that the action listener i add only changes the button background, text, and size (to fit new text).

Here is the action listener as of right now. login is the JButton:

private class LoginListener implements ActionListener{

  public void actionPerformed(ActionEvent e){

    loggedIn = !loggedIn;

    if(loggedIn){
      login.setText("Logout");
      login.setBackground(Constants.RED);
    }
    else{
      login.setText("Login");
      login.setBackground(Constants.UPPER_BOUNDARY);
    }

    login.setSize(login.getPreferredSize());
  }
}

The setup is this. The action listener is a subclass of the loginPanel where the login button is located. That loginPanel is added to the main JFrame at the upper 1/4 of the frame. The lower 3/4 of the main JFrame is mainPanel which has other swing components. The loginPanel and mainPanel do not share components or variables or really know of each other’s existence (as far as I have coded). Yet when this actionlistener above is added to the login button components in the mainPanel shift from their positions to other positions. The only happens at first click and then they stay where they are at (not where i want them).

Other factors:
– I use absolute positioning (sorry if you don’t like it but I like it better)
– I am using a SynthLookAndFeel but have never had this issue with this look and feel before.

Thanks

  • 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-05T00:43:15+00:00Added an answer on June 5, 2026 at 12:43 am

    Other factors: – I use absolute positioning (sorry if you don’t like it but I like it better)

    There’s nothing to be sorry about, and the solution is simple: Don’t use absolute positioning, but instead learn about and use the layout managers to there full abilities. One of the reasons to use them is to avoid pernicious bugs like this one. It’s quite possible that your code is in fact using a component’s default layout manager even now without you knowing about it. You can find out more about them here. One of the keys to using them well is to nest them by using nested JPanels, each using its own layout manager. Then they can do the heavy layout lifting for you automatically.

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

Sidebar

Related Questions

I have searched but can't find why this simple code will fail in Drools
I have searched the site and I haven't found an answer to my problem.
I have searched here, but haven't found any question related to this. I got
I've searched google and SO for a solution to this problem but have not
So I have searched for this but not finding anything about it and if
I've searched around and haven't found an answer to this. What I would like
I've searched all over for a solution to this (including SO), however still haven't
I've searched for this on different places but I haven't found an exhaustive answer.
I have searched (probed ,even) for an answer to this but haven't come up
I have searched this site for an answer and found many responses to unsigned/signed

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.