title: Adjust the label, text-field & button size
body: <p>I have written the code for <code>AmortizationLoanSchedule</code> in Swing but the look is not good.  How to adjust the sizes of the labels , text-field &amp; button?</p>
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JApplet;
  import javax.swing.JButton;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  import javax.swing.JTextField;
  import javax.swing.border.TitledBorder;
  
  public class AmortizationLoanSchedule extends JApplet implements ActionListener {
  
      private JLabel LoanAmount = new JLabel(&quot;Loan Amount&quot;);
      private JLabel NumberOfYears = new JLabel(&quot;Number Of Years&quot;);
      private JLabel InterestRate = new JLabel(&quot;Interest Rate (Annual)&quot;);
  
      private JTextField jtfLoanAmount = new JTextField(10);
      private JTextField jtfNumberOfYears = new JTextField(10);
      private JTextField jtfInterestRate = new JTextField(10);
  
      // Calculate button is also needed
      private JButton jbtCalculate = new JButton(&quot;Amortize Loan&quot;);
  
      // ...and a text area where the results will be displayed
      private JTextArea jtaResults = new JTextArea();
  
      public void init() {
          try {
              // Panel p1 will hold the input
              JPanel p1 = new JPanel();
              p1.setLayout(new GridLayout(3, 3));
              p1.add(LoanAmount);
              p1.add(jtfLoanAmount);
              p1.add(NumberOfYears);
              p1.add(jtfNumberOfYears);
              p1.add(InterestRate);
              p1.add(jtfInterestRate);
  
              // Panel p2 will hold panel p1 and the calculate button
              JPanel p2 = new JPanel();
              p2.setLayout(new BorderLayout());
              p2
                      .setBorder(new TitledBorder(
                              &quot;Enter loan amount, Number of years and annual interest rate&quot;));
              p2.add(p1, BorderLayout.BEFORE_FIRST_LINE);
              p2.add(jbtCalculate, BorderLayout.AFTER_LAST_LINE);
  
              // Action listener for the button
              jbtCalculate.addActionListener(this);
  
              // Make the text area scrollable and uneditable
              JScrollPane scrollPane = new JScrollPane(jtaResults);
              jtaResults.setRows(12);
              jtaResults.setEditable(false);
  
              // Place the two panels to the applet
              getContentPane().add(p2, BorderLayout.NORTH);
              getContentPane().add(scrollPane, BorderLayout.SOUTH);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      public void actionPerformed(ActionEvent e) {
          if (e.getSource() == jbtCalculate)
              calculateLoan();
          else
              System.out.println(&quot;you will never see this text!&quot;);
  
      }
  
      public void calculateLoan() {
          if ((jtfNumberOfYears.getText().equals(&quot;&quot;))
                  || (jtfLoanAmount.getText().equals(&quot;&quot;))
                  || (jtfInterestRate.getText().equals(&quot;&quot;))) {
              JOptionPane.showMessageDialog(null, &quot;All fields are mandatory&quot;,
                      null, 1);
          } else {
              int numberOfYears = Integer.parseInt(jtfNumberOfYears.getText());
              double loanAmount = Double.parseDouble(jtfLoanAmount.getText());
              double annualInterestRate = (Double.parseDouble(jtfInterestRate
                      .getText())) / 100;
  
              double monthlyInterestRate = annualInterestRate / 12;
              double numberOfMonths = numberOfYears * 12;
              double monthlyPayment = loanAmount
                      * (monthlyInterestRate / (1 - Math.pow(
                              1 + monthlyInterestRate, -numberOfMonths)));
              double totalPayment = monthlyPayment * numberOfMonths;
              double balance = loanAmount;
              double interest;
              double principal;
  
              jtaResults.append(&quot;Payment#\t&quot; + &quot;Interest\t&quot; + &quot;Principal\t&quot;
                      + &quot;Balance\n\n&quot;);
  
              for (int i = 0; i &lt; numberOfYears * 12; i++) {
                  interest = (int) (monthlyInterestRate * balance * 100) / 100.0;
                  principal = (int) ((monthlyPayment - interest) * 100) / 100.0;
                  balance = (int) ((balance - principal) * 100) / 100.0;
  
                  jtaResults.append(i + 1 + &quot;\t&quot; + interest + &quot;\t&quot; + principal
                          + &quot;\t&quot; + balance + &quot;\n&quot;);
              }
  
              jtaResults.append(&quot;\n\nMonthly Payment: $&quot;
                      + (int) (monthlyPayment * 100) / 100.0 + &quot;\n&quot;);
              jtaResults.append(&quot;Total Payment: $&quot; + (int) (totalPayment * 100)
                      / 100.0 + &quot;\n\n&quot;);
          }
      }
  }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/ByZyG.png" alt="AmortizationLoanSchedule" /></p>
  <h2>Update</h2>
  <p>This is what is required.</p>
  <p><img src="https://i.stack.imgur.com/peY9Z.png" alt="enter image description here" /></p>