Java: Determine JFrame/Window-Size in Null-Layout

254 views Asked by At

I have the following java problem:

I definitively have to use a null layout set by

mainWindow.getContentPane().setLayout(null);

with mainWindow being a JFrame. Now, I want to place objects (JLabel for example) absolutely but depending on the window size. For that, I have to determine the size of the JFrame or that of the contentPane. Is there any way to get that information in a null-layout?

I have tried:

mainWindow.getContentPane().getBounds();
mainWindow.getContentPane().getPreferredSize();
mainWindow.getContentPane().getSize();
mainWindow.getContentPane().getInsets();

And the same for mainWindow itself. But for all of them, I just get zeros.

Either google holds no answer or I've looked for the wrong keywords.

I would be glad to get any advice or link to a solution. Thanks.

0

There are 0 answers