title: How returns XxxSize from JComponent(s) added to the JLabel
body: <p>how can I correctly returns XxxSize from JComponent(s) added to the JLabel</p>
  
  <p>1st. figure >> <code>lets LayoutManager works like as for JPanel, JLabel returns Size(0, 0)</code> </p>
  
  <p><img src="https://i.stack.imgur.com/HVySy.jpg" alt="enter image description here"></p>
  
  <p>2nd. figure >> <code>added some PreferredSize to the JLabel</code></p>
  
  <p><img src="https://i.stack.imgur.com/4KcVE.jpg" alt="enter image description here"></p>
  
  <p>3rd. figure >> <code>calculated PreferredSize from JComponent(s) added to the JLabel</code> </p>
  
  <p><img src="https://i.stack.imgur.com/hI0sK.jpg" alt="enter image description here"></p>
  
  <p>4th. figure >> <code>lets LayoutManager works changed JLabel to JPanel, now LayoutManager correctly calculated Dimension without using any XxxSize</code> </p>
  
  <p><img src="https://i.stack.imgur.com/mRREc.jpg" alt="enter image description here"></p>
  
  <p>notice sice there is used Nimbus L&amp;F, same output is there for all accesible L&amp;F </p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.util.LinkedList;
  import java.util.Queue;
  import javax.swing.*;
  
  public class NimbusBorderPainterDemo extends JFrame {
  
      private static final long serialVersionUID = 1L;
      private JFrame frame = new JFrame();
      private JPanel fatherPanel = new JPanel(), titlePanel = new JPanel();
      private JLabel buttonPanel = new JLabel();
  
  
      //figure  ---&gt; 4th. switch JLabel with JPanel
      //private JPanel buttonPanel = new JPanel();
      private Queue&lt;Icon&gt; iconQueue = new LinkedList&lt;Icon&gt;();
  
      public NimbusBorderPainterDemo() {
          iconQueue.add(UIManager.getIcon("OptionPane.errorIcon"));
          iconQueue.add(UIManager.getIcon("OptionPane.informationIcon"));
          iconQueue.add(UIManager.getIcon("OptionPane.warningIcon"));
          JButton button0 = createButton();
          JButton button1 = createButton();
          JButton button2 = createButton();
          button2.addActionListener(new ActionListener() {
  
              public void actionPerformed(ActionEvent e) {
                  System.exit(1);
              }
          });
          int gap = 5;
          buttonPanel.setLayout(new GridLayout(0, 3, gap, 0));
          buttonPanel.add(button0);
          buttonPanel.add(button1);
          buttonPanel.add(button2);
  
          // figure 1st. ---&gt;  without PreferredSize
  
          // figure 2nd. ---&gt;
          //buttonPanel.setPreferredSize(new Dimension(160, 30));
  
          // figure 3rd. ---&gt;
          /*Dimension dim = button0.getPreferredSize();
          int w = dim.width;
          int h = dim.height;
          w = (w + 5) * 3;
          h += 4;
          dim = new Dimension(w, h);
          buttonPanel.setPreferredSize(dim);*/
  
          titlePanel.setLayout(new BorderLayout());
          titlePanel.add(new JLabel(nextIcon()), BorderLayout.WEST);
          titlePanel.add(new JLabel("My Frame"), BorderLayout.CENTER);
          titlePanel.setBorder(BorderFactory.createLineBorder(Color.GRAY));
          titlePanel.add(buttonPanel, BorderLayout.EAST);
          fatherPanel.setLayout(new BorderLayout());
          fatherPanel.add(titlePanel, BorderLayout.CENTER);
          frame.setUndecorated(true);
          frame.add(fatherPanel);
          frame.setLocation(50, 50);
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          frame.setVisible(true);
      }
  
      private JButton createButton() {
          JButton button = new JButton();
          button.setBorderPainted(false);
          button.setBorder(null);
          button.setFocusable(false);
          button.setMargin(new Insets(0, 0, 0, 0));
          button.setContentAreaFilled(false);
          button.setIcon(nextIcon());
          //button.setRolloverIcon(nextIcon());
          //button.setPressedIcon(nextIcon());
          //button.setDisabledIcon(nextIcon());
          nextIcon();
          return button;
      }
  
      private Icon nextIcon() {
          Icon icon = iconQueue.peek();
          iconQueue.add(iconQueue.remove());
          return icon;
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
  
              @Override
              public void run() {
                  try {
                      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
                  } catch (Exception fail) {
                  }
                  UIManager.getLookAndFeelDefaults().put("nimbusFocus", Color.RED);
                  NimbusBorderPainterDemo nimbusBorderPainterDemo = new NimbusBorderPainterDemo();
              }
          });
      }
  }
  </code></pre>