title: how to add jlabel one below the other on jbutton click
body: <p>I wanted to add jlabel dynamically on button click right below the other. I am not able to figure out the layout to be used in order to add jlabel. Any hint or solution will be appreciated</p>
  
  <p><strong>Code goes here</strong></p>
  
  <pre><code>    package com.vastu;
  
  import javax.swing.JPanel;
  
  public class spanel extends JPanel {
  
      String[] nakshatras = {"SELECT","Ashwini","Bharani","Kritika","Rohini","Mrugashira","Aardra","Punarvasu","Pushya","Aashlesha","Magha","Poorva","Phalguni","Uttara","Phalguni","Hasta","Chitra","Swati","Vishakha","Anuradha","Jyeshta","Moola","Poorvashada","Uttarashada","Shravana","Dhanishta","Shatabhisha","Poorvabhadra","Uttarabhadra","Revati"};
      String[] more={"MORE MEMBERS","FATHER","MOTHER","HUSBAND","WIFE","SON","DAUGHTER"};
      public spanel() {
          setBackground(new Color(147, 112, 219));
          setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  
          JLabel lblTarabala = new JLabel("tarabala:");
          add(lblTarabala);
  
          JLabel lblStarOfOwner = new JLabel("STAR OF OWNER  :");
          add(lblStarOfOwner);
  
          JComboBox comboBox = new JComboBox(nakshatras);
          add(comboBox);
  
          JComboBox comboBox_1 = new JComboBox(more);
          add(comboBox_1);
  
          comboBox_1.addActionListener(new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
                  JComboBox jc = (JComboBox) e.getSource();
                  Integer i=jc.getSelectedIndex();
                  if(i==0){
                      repaint();
                  }else if(i==1){
                      JLabel newmember=new JLabel();
                      JComboBox star_f=new JComboBox(nakshatras);
                      GridBagConstraints gbc_starf = new GridBagConstraints();
                      star_f.setBackground(new Color(211, 211, 211));
                      newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
                      newmember.setText("STAR OF FATHER  :");
                      newmember.setBackground(new Color(147, 112, 219));
                      gbc_starf.gridwidth=5;
                      add(newmember);
                      add(star_f);
                      revalidate();
                  }else if(i==2){
                      JLabel newmember=new JLabel();
                      JComboBox star_m=new JComboBox(nakshatras);
                      GridBagConstraints gbc_starm = new GridBagConstraints();
                      star_m.setBackground(new Color(211, 211, 211));
                      newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
                      newmember.setText("STAR OF MOTHER  :");
                      newmember.setBackground(new Color(147, 112, 219));
                      gbc_starm.gridwidth=5;
                      add(newmember);
                      add(star_m);
                      revalidate();
                  }else if(i==3){
                      JLabel newmember=new JLabel();
                      JComboBox star_h=new JComboBox(nakshatras);
                      GridBagConstraints gbc_starh = new GridBagConstraints();
                      star_h.setBackground(new Color(211, 211, 211));
                      newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
                      newmember.setText("STAR OF HUSBAND  :");
                      newmember.setBackground(new Color(147, 112, 219));
                      gbc_starh.gridwidth=5;
                      add(newmember);
                      add(star_h);
                      revalidate();
                  }
  
              }
          });
  
      }
  }
  </code></pre>
  
  <hr>
  
  <p>here i used box layout but the fields appear on full screen. as
  <img src="https://i.stack.imgur.com/n7ymv.jpg" alt="enter image description here"></p>
  
  <hr>
  
  <p>How am i supposed to custom resize component in boxlayout?</p>