title: Aligning JLabel and JTextField in BorderLayout
body: <p>I am just trying Java <code>BorderLayout</code> and <code>GridLayout</code> with some GUI components. </p>
  
  <p>I am trying for right-align of  <code>JLabel</code>s and left-align the <code>JTextField</code>s so that it can be much of better in look. </p>
  
  <p>I found some answers in stackoverflow itself, with the help of <code>setAlignmentX</code> and <code>setHorizontalAlignment</code>. Both didn't work. </p>
  
  <p>Basically, I have 3 components in each <code>BorderLayout</code>. </p>
  
  <ol>
  <li>JLabel</li>
  <li>JTextField</li>
  <li>JButton</li>
  </ol>
  
  <p>Then, these components are being added to a <code>GridLayout</code> on each row.</p>
  
  <p><img src="https://i.stack.imgur.com/ihueM.png" alt="enter image description here"></p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.GridLayout;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  
  /**
   *
   * @author dinesh
   */
  public class MySettings {
  
      public static void main(String[] args) {
          JFrame jf = new JFrame("hi");
  
          //demo Info Panel start
          // &lt;editor-fold defaultstate="collapsed" desc="demo info panel"&gt;
          JLabel lbldemoExecutablePath = new JLabel("demo Executable Path :");
  //        lbldemoExecutablePath.setAlignmentX(JLabel.LEADING);
  //        lbldemoExecutablePath.setAlignmentY(JLabel.LEADING);
  //        lbldemoExecutablePath.setHorizontalAlignment(SwingConstants.CENTER);
  
          JTextField txtdemoInstallationPath = new JTextField(10);
          txtdemoInstallationPath.setEditable(false);
          txtdemoInstallationPath.setBackground(Color.WHITE);
          txtdemoInstallationPath.setToolTipText("getdemoPath()");
          txtdemoInstallationPath.setAlignmentX(JLabel.LEADING);
          txtdemoInstallationPath.setAlignmentY(JLabel.LEADING);
  
          JButton btndemoBrowse = new JButton("Browse");
  
          btndemoBrowse.addActionListener(new java.awt.event.ActionListener() {
              @Override
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.out.println("demo browse button clicked");
              }
          });
  
          JPanel pnldemoInfo = new JPanel(new BorderLayout(10, 10));
          pnldemoInfo.add(lbldemoExecutablePath, BorderLayout.LINE_START);
          pnldemoInfo.add(txtdemoInstallationPath, BorderLayout.CENTER);
          pnldemoInfo.add(btndemoBrowse, BorderLayout.LINE_END);
          // &lt;/editor-fold&gt;
          //demo info panel end
  
          //sample Info Panel start
          // &lt;editor-fold defaultstate="collapsed" desc="sample info panel"&gt;
          JLabel lblsampleExecutablePath = new JLabel("sample Executable Path :");
  //        lblsampleExecutablePath.setAlignmentX(JLabel.LEADING);
  //        lblsampleExecutablePath.setAlignmentY(JLabel.LEADING);
          JTextField txtsampleInstallationPath = new JTextField(10);
          txtsampleInstallationPath.setEditable(false);
          txtsampleInstallationPath.setBackground(Color.WHITE);
          txtsampleInstallationPath.setToolTipText("getsamplePath()");
  
  
          JButton btnsampleBrowse = new JButton("Browse");
  
          btnsampleBrowse.addActionListener(new java.awt.event.ActionListener() {
              @Override
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.out.println("demo browse button clicked");
              }
          });
  
          JPanel pnlsampleInfo = new JPanel(new BorderLayout(10, 10));
          pnlsampleInfo.add(lblsampleExecutablePath, BorderLayout.LINE_START);
          pnlsampleInfo.add(txtsampleInstallationPath, BorderLayout.CENTER);
          pnlsampleInfo.add(btnsampleBrowse, BorderLayout.LINE_END);
          // &lt;/editor-fold&gt;
          //sample info panel end
  
          //app Info Panel start
          // &lt;editor-fold defaultstate="collapsed" desc="app info panel"&gt;
          JLabel lblappExecutablePath = new JLabel("app Executable Path :");
  //        lblappExecutablePath.setAlignmentX(JLabel.LEADING);
          JTextField txtappExecutablePath = new JTextField(10);
          txtappExecutablePath.setEditable(false);
          txtappExecutablePath.setBackground(Color.WHITE);
          txtappExecutablePath.setToolTipText("gettxtappExecutablePath()");
  
          JButton btnappBrowse = new JButton("Browse");
  
          btnappBrowse.addActionListener(new java.awt.event.ActionListener() {
              @Override
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.out.println("appBrowse browse button clicked");
              }
          });
  
          JPanel pnlappInfo = new JPanel(new BorderLayout(10, 10));
          pnlappInfo.add(lblappExecutablePath, BorderLayout.LINE_START);
          pnlappInfo.add(txtappExecutablePath, BorderLayout.CENTER);
          pnlappInfo.add(btnappBrowse, BorderLayout.LINE_END);
          // &lt;/editor-fold&gt;
          //app info panel end
  
          //logfile Info Panel start
          // &lt;editor-fold defaultstate="collapsed" desc="logfile info panel"&gt;
          JLabel lblLogFilePath = new JLabel("Log File Path :");
  //        lblLogFilePath.setAlignmentX(JLabel.LEADING);
          JTextField txtLogFilePath = new JTextField(10);
          txtLogFilePath.setEditable(false);
          txtLogFilePath.setBackground(Color.WHITE);
          txtLogFilePath.setToolTipText("gettxtLogFilePath()");
  
          JButton btnLogFileBrowse = new JButton("Browse");
  
          btnLogFileBrowse.addActionListener(new java.awt.event.ActionListener() {
              @Override
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.out.println("appBrowse browse button clicked");
              }
          });
  
          JPanel pnlLogFileInfo = new JPanel(new BorderLayout(10, 10));
          pnlLogFileInfo.add(lblLogFilePath, BorderLayout.LINE_START);
          pnlLogFileInfo.add(txtLogFilePath, BorderLayout.CENTER);
          pnlLogFileInfo.add(btnLogFileBrowse, BorderLayout.LINE_END);
          // &lt;/editor-fold&gt;
          //logfile info panel end
  
          JPanel pnlGereal = new JPanel(new GridLayout(0, 1));
          pnlGereal.add(pnldemoInfo);
          pnlGereal.add(pnlsampleInfo);
          pnlGereal.add(pnlappInfo);
          pnlGereal.add(pnlLogFileInfo);
  
          jf.add(pnlGereal);
          jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          //jf.setSize(500, 500);
  
          jf.pack();
          jf.setVisible(true);
      }
  
  }
  </code></pre>
  
  <p>Where am I making the mistake ?  Where I exactly set the alignment ? </p>