Getting the correct sizes for JComponent after using GroupLayout

I wanted to ask whether it is possible to get the correct sizes of an JPanel after it has been placed in another JPanel that uses GroupLayout as Layout Manager. I have already tried to use:

.getPreferredSize(): this results in the Preferred Size that has been set by me, not the actual size that is drawn on the JPanel in the frame (if frame get's resized, the element will expand horizontally; which is not seen in the values).

.getSize(): it returns 0.

.getHeight(): it returns 0.

.getWidth(): it returns 0.

Maybe the positioning of the code is relevant, but it is executed AFTER shown on screen so it should not matter.

To force it to do that after it is shown on screen, maybe I can use EventQueue, but I'm not sure how.

Thank you for your answers!

Answers


You can get the "correct" size of the component only after it has been rendered, either by calling pack or setVisible(true) on the top level container.

Maybe the positioning of the code is relevant, but it is executed AFTER shown on screen so it should not matter.

Then something's not right. Are you sure that you're calling these methods on the visible components and not some variables that shadow them? Without code it's hard to tell where your error lies.


Need Your Help

Forcing file to download in CodeIgniter FTP class

php codeigniter

I am using the FTP class in CodeIgniter, they have a function for downloading the file from the FTP, however, its only to the server itself. I am trying to get it to download straight to the user.

How to generate unique filenames for uploaded pictures

php javascript mysql

I store uploaded pictures in a folder while I store the path and filename in a database. Please how best can I generate unique filenames to avoid name conflict in the folder? Thanks

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.