title: Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared
body: <p>I'm getting this error on this code:</p>
  
  <pre><code>    super("Trace Masker");
      setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
  
      label1 = new JLabel("Source directory:");
      label2 = new JLabel("Target directory:");
      label3 = new JLabel("Defect number:");
      label4 = new JLabel("Slice tokens:");
      label4.setToolTipText("Seperate multiple tokens with comma");
  
      txtSourceDirectory = new JTextField(30);
      txtTargetDirectory = new JTextField(30);
      txtDefectNumber = new JTextField(30);
      txtSliceTokens = new JTextField(30);
  
      btnBrowseSourceDirectory = new JButton("...");
      btnBrowseTargetDirectory = new JButton("...");
      btnStart = new JButton("Start");
      btnCancel = new JButton("Cancel");
  
      pnlLabels = new JPanel(new BoxLayout(pnlLabels, BoxLayout.PAGE_AXIS));
      pnlText = new JPanel(new BoxLayout(pnlText, BoxLayout.PAGE_AXIS));
      pnlBrowseButtons = new JPanel(new BoxLayout(pnlBrowseButtons, BoxLayout.PAGE_AXIS));
      pnlTop = new JPanel(new BoxLayout(pnlTop, BoxLayout.LINE_AXIS));
      pnlActionButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  
      pnlLabels.add(label1);
      pnlLabels.add(label2);
      pnlLabels.add(label3);
      pnlLabels.add(label4);
  
      pnlText.add(txtSourceDirectory);
      pnlText.add(txtTargetDirectory);
      pnlText.add(txtDefectNumber);
      pnlText.add(txtSliceTokens);
  
      pnlBrowseButtons.add(btnBrowseSourceDirectory);
      pnlBrowseButtons.add(btnBrowseTargetDirectory);
  
      pnlTop.add(pnlLabels);
      pnlTop.add(pnlText);
      pnlTop.add(pnlBrowseButtons);
  
      pnlActionButtons.add(btnStart);
      pnlActionButtons.add(btnCancel);
  
      add(pnlTop);
      add(pnlActionButtons);
  </code></pre>
  
  <p>The error is on this line:</p>
  
  <pre><code>pnlLabels.add(label1);
  </code></pre>
  
  <p>Just to check if this related specifically to pnlLabels, I commented all of it's lines. The error then happens on: </p>
  
  <pre><code>pnlText.add(txtSourceDirectory);
  </code></pre>
  
  <p>I've already checked the other 2 questions here about this and fixed the setLayout declaration for the JFrame:
  <a href="https://stackoverflow.com/questions/5917017/java-awt-awterror-boxlayout-cant-be-shared">Question1</a>
  <a href="https://stackoverflow.com/questions/761341/boxlayout-cant-be-shared-error">Question2</a></p>