The panel returns 0, 0 because it is just the default value.
When you add a panel to the frame and call pack() in the frame, it will calculate the correct (preferred) size and set it. Until then, you cannot find the size because it has not been calculated.
Why do you need these values? If you can explain the problem in a broader sense, we can help you.
source share