title: Curious behavior of java.awt.Component, setVisible(), LayoutManager
body: <p>I was trying to create a GUI and found some curious behavior of java.awt.Component. I wanted to <code>setVisible(true)</code>/<code>setVisible(false)</code> an java.awt.Component by an external Event. But this only works when the to be switched Component was already visible in the first place. Attached, I provided a minimal replica of my problem.</p>
  <pre><code>package test;
  
  import java.awt.Button;
  import java.awt.Dimension;
  import java.awt.Frame;
  import java.awt.Menu;
  import java.awt.MenuBar;
  import java.awt.MenuItem;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  
  public final class Test {
      public static void main(String[] args) {
          Button testButton = new Button(&quot;Test Button&quot;);
          testButton.setVisible(false); /* Removing this line makes the code to work as intended, but why? */
          
          Frame mainFrame = new Frame(&quot;Test&quot;);
          mainFrame.setMinimumSize(new Dimension(640, 480));
          mainFrame.setVisible(true);
          mainFrame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent event) {
                  System.exit(0);
              }
          });
          
          mainFrame.add(testButton);
          
          mainFrame.setMenuBar(new MenuBar());
          mainFrame.getMenuBar().add(new Menu(&quot;Test&quot;));
          mainFrame.getMenuBar().getMenu(0).add(new MenuItem(&quot;Show/Hide \&quot;Test Button\&quot;&quot;));
          mainFrame.getMenuBar().getMenu(0).getItem(0).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                  if(testButton.isVisible()) testButton.setVisible(false);
                  else testButton.setVisible(true);
                  System.out.println(&quot;testButton.getBounds()&quot; + testButton.getBounds()); /* EDIT: Added this line for debugging. */
                  System.out.println(&quot;testButton.isVisible() &quot; + testButton.isVisible());
              }
          });
      }
  }
  </code></pre>
  <p>When you remove line <code>testButton.setVisible(false);</code>, testButton is viewable and also switchable in its state of visibility, otherwise not. Does anyone know why? Maybe the layout-manager doesn't work with invisible components?</p>
  <p>EDIT: It seems the layout-manager doesn't <code>setBounds(...)</code> for invisible components, but why?</p>