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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:22:46+00:00 2026-06-03T07:22:46+00:00

I have a class MyPanel that extends JPanel . MyPanel is a child panel:

  • 0

I have a class MyPanel that extends JPanel.
MyPanel is a child panel: his size is dinamically calculated by the LayoutManager of his parent.
The problem is that I need MyPanel to be notified as soon as the LayoutManager of his parent calculates his size.
It needs to be notified because I need to initialize some variables according to the panel’s size.

If I call getSize() in the MyPanel constructor i get (0,0) because the panel is not “ready”.
When should i call getSize()?

I’d like to have something like this:

/** Lays out the panel and sets his size according to his layout */
@Override
public void onReady() {
    System.out.println(getSize()); //output is (0,0);
    super.onReady();
    System.out.println(getSize()); //output is (600,500);
    //here i can initialize my variables
}

Is there something similar? Maybe doLayout()?

The only way i could find is calling getSize() in the paintComponent() method… it surely works because the panel is surely displayed when paintComponent() is called but I can’t do this because i need to initialize some variables as soon as i know the panel size… but only once! paintComponent() will be called several times…

  • 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-03T07:22:48+00:00Added an answer on June 3, 2026 at 7:22 am

    It’s ComponentListener.componentResized().

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

Sidebar

Related Questions

I have a class that extends JPanel with several buttons on it. I would
So, I have an abstract class Panel and an implementation of it MyPanel .
I have class method that returns a list of employees that I can iterate
I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is
I have class with a member function that takes a default argument. struct Class
basically, I have a program that has a class to create a basic GUI,
I have a JScrollPane with a JPanel that implements Scrollable as its viewport view.
Trying to solve this problem: I have the following set of divs that when
I have a wxPython frame, with a Panel. In my Panel class, I have
I have to edit data inside my template that is use for Ext.Panel. How

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.