title: How to find out the preferred size of a JPanel which is not displayed, according to its content?
body: <p>I am using a JPanel (with several labels inside) to add a dynamic information on a graph. This panel is dynamically created, it is not visible before I use it to draw.</p>
  
  <p>For this, I am using a BufferedImage, and I follow approximately the same steps as described on this <a href="https://stackoverflow.com/questions/1349220/convert-jpanel-to-image">other question</a>. It works good, as long as I specify all sizes (the panel, and its components).</p>
  
  <p>Like asked as well in comments of the referred question, how can I determine the optimal size of this panel? The same operation would be done if this panel was displayed in a regular frame/layout setting. </p>
  
  <p>In my case, how can I "pack", in a way, this panel, so that its size, and size of its content are set to the optimal (determined by the size of labels, then)?</p>