Component disappears randomly in the SOUTH position when using BorderLayout and pack()
<p>I have a rather mysterious problem when using BorderLayout. When I place a JButton in the CENTER position and a component (say JLabel) in the SOUTH, the latter one disappears randomly. Here is an example. To see the problem you'll have to resize the window to a larger size and then move your mouse cursor all over the screen a bit (on an off the button, label, window title bar, Windows Taskbar, edges of the screen). You don't need to press the button. After a few seconds of such movements the label disappears. It only reappears if you resize or minimize/restore the window again.</p>

<p>The strange thing is, pack() seems to be important, I don't observe the problem in I use e.g. setSize(600,300) on my JFrame instead. Also it seems that the CENTER component must be a JButton, while the SOUTH component can be anything (I tried JLabel, JCheckBox), and the positions (SOUTH and CENTER) are important. Does not happen if the button is placed NORTH, for example.</p>

<p>It would be easy to avoid this situation in practice, of course, but still I would like to know why it happens, and whether I did anything wrong or unsafe. I am using JDK 8 release 77 on Windows 10.</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;  

public class MyExample extends JFrame{
 MyExample() { initGUI();} // Constructor

 private void initGUI(){
  // Create the button
  JButton myButton=new JButton("Press ME !"); 

  // Create the label
  JLabel testLabel=new JLabel("TEST !!!");

  // Set up the window 
  JPanel pane=(JPanel) getContentPane();
  pane.setLayout(new BorderLayout());

  pane.add(myButton,BorderLayout.CENTER);
  pane.add(testLabel,BorderLayout.SOUTH); 

  setDefaultCloseOperation(EXIT_ON_CLOSE);
  pack();   
  // setSize(600,300);  

 }

 public static void main(String[] args){
  EventQueue.invokeLater(()-&gt;{
   MyExample me=new MyExample();
   me.setVisible(true);
  });  
 }
}
</code></pre>

<p>Note: I defined the JPanel object pane for clarity, but if I simply write instead</p>

<pre><code>  // Set up the window 
  add(myButton,BorderLayout.CENTER);
  add(testLabel,BorderLayout.SOUTH); 
</code></pre>

<p>the result is exactly the same.</p>