title: How do I align my checkboxes in a GridLayout?
body: <p>I need to align the checkboxes in my GUI, but I'm having trouble finding the right command or method. I have written a short example that is simpler to read:</p>
  
  <pre><code>public class GUI {
  
  JFrame window = new JFrame();
  JPanel mainPanel = new JPanel();
  JPanel[] rowPanel = new JPanel[5];
  JCheckBox[] check = new JCheckBox[5];
  
  public GUI () { 
          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          window.setExtendedState(window.MAXIMIZED_BOTH);
          window.setVisible(true);
          window.add(mainPanel);
          mainPanel.setLayout(new GridLayout(5, 1));
  
          for(int i = 0; i &lt; 5; i++) 
          {
          rowPanel[i] = new JPanel();
          mainPanel.add(rowPanel[i]);
          }
  
          check[0] = new JCheckBox("red");
          check[1] = new JCheckBox("violet");
          check[2] = new JCheckBox("pink");
          check[3] = new JCheckBox("magenta");
          check[4] = new JCheckBox("every color");
  
          for(int i = 0; i &lt; 5; i++) 
          {
              rowPanel[i].add(check[i]);
          }   
      }
  }
  </code></pre>
  
  <p>I have tried <code>.setHorizontalTextPosition()</code> and <code>.setHorizontalAlignment()</code>, but neither have worked. I want all of the boxes to be aligned vertically on the right side of their labels.</p>