title: Vertical alignment of components of jpanels using GridLayout
body: <p>I am making KenKen as my term project using java swing library. For alignment I have used gridbag and gridlayout, But now i want to add one more component of JPanel to the UI. These screenshots will make the problem more clear:</p>
  
  <p><a href="https://i.stack.imgur.com/0Pm7R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Pm7R.png" alt="Before I click on the button in the lowest panel below"></a>
  </p>
  
  <p>Now I select the grid cell to which i want to add respective candidates of in the left most panel.</p>
  
  <p><a href="https://i.stack.imgur.com/6TbME.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6TbME.png" alt="This is what happens when I click the number buttons 2, 3, 4"></a>
  </p>
  
  <p>It disturbs the adjacent alignments of the grid and panels.</p>
  
  <p>Here are the panels with their respective layouts:</p>
  
  <pre><code> JPanel buttonPanel = new JPanel();
   buttonPanel.setLayout(new GridLayout(1, 4, 5, 5));
   buttonPanel.setPreferredSize(new Dimension(20,40));
   buttonPanel.add(undoButton);
   buttonPanel.add(redoButton);
   buttonPanel.add(eraseButton);
   buttonPanel.add(hintButton);
  
   JPanel cellPanel = new JPanel();
   cellPanel.setName("cellPanel");
   cellPanel.setLayout(new GridLayout(pSize, pSize, 0, 0));
  
   JPanel numPanel = new JPanel();
   numPanel.setName("numPanel");
   numPanel.setLayout(new GridLayout(1,1,5,5));
   numPanel.setPreferredSize((new Dimension(50,60)));
  
   JPanel candPanel = new JPanel();
   candPanel.setName("candidatesPanel");
   JLabel candidates = new JLabel("Candidates");
   candidates.setFont(new Font("Courier New", Font.ITALIC, 14));
   candidates.setForeground(Color.GRAY);
   candPanel.setLayout(new GridLayout(0,1));
   candPanel.add(candidates);
  </code></pre>
  
  <p>Then it all goes into the content panel:</p>
  
  <pre><code> content.add(buttonPanel, pos.nextCol().expandW());
   content.add(candPanel, pos.nextRow());
   content.add(new Gap(GAP) , pos.nextRow());  // Add a gap below
   content.add(cellPanel, pos.nextCol());
   content.add(numPanel,pos.nextCol().expandW());
  </code></pre>
  
  <p>The buttons are all generated on runtime, and they are added to the candPanel in an action listener.</p>