Hello,

This code doesn't work correctly.
It add buttons at the end, and delete too from the end.
The delete button works once.

Java Code:
import java.awt.BorderLayout;
	public class Test_DG extends JFrame {
	private JPanel contentPane;
	static int nbrows;
	JPanel columnPanel = new JPanel();
	JButton btnStart = new JButton("Start");
	ArrayList<JPanel> listRowPanel= new ArrayList<JPanel>();
	private final JButton button_1 = new JButton("New button");;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		nbrows=0;
		Test_DG frame = new Test_DG();
		frame.setVisible(true);	 
	}

	/**
	 * Create the frame.
	 */
	public Test_DG() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 637, 441);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		btnStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addRow();
			}
		});
		btnStart.setBounds(349, 21, 78, 23);
		contentPane.add(btnStart);
		columnPanel.setBounds(29, 24, 310, 368);
		contentPane.add(columnPanel);
		
		columnPanel.setBackground(Color.ORANGE);
		columnPanel.setLayout(new GridLayout(13, 1, 0, 2));
		
		JButton button = new JButton("New button");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				columnPanel.removeAll();
				
			}
		});
		button.setBounds(349, 71, 89, 23);
		contentPane.add(button);
			
	}
	
	  void addRow() {
		   
		    JPanel rowPanel = new JPanel();
		    rowPanel.setLayout(null);
		    
		    JButton lbl = new JButton("");
			Random randGen = new Random();
		    lbl.setText("N"+nbrows +" "+randGen.nextInt(8) +randGen.nextInt(8));

		    lbl.setBounds(0, 3, 95, 18);
		    rowPanel.add(lbl);

		    JButton btnUp = new JButton("^");
		    btnUp.setBounds(95, 3, 45, 18);
			rowPanel.add(btnUp);
			
			JButton btnDown = new JButton("V");
			btnDown.setBounds(139, 3, 45, 18);
			rowPanel.add(btnDown);
			
		    JButton btnDel = new JButton("Del");
		    btnDel.setBounds(185, 3, 55, 18);
			rowPanel.add(btnDel);
			/////////////////////////////////////////
			btnDel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent ev) {
					int index=0;
					Container d=( (JButton) ev.getSource()).getParent();
					 Iterator<JPanel> itr = listRowPanel.iterator();
					    while (itr.hasNext()) 
					    {
					      JPanel element = itr.next();
					      	if (element.equals(d))
					      		{
					      		//System.out.println(element+" true" );
					      		System.out.println("index of del : "+ index );
					      		}
					      	index++;	 
					    }
					Component[]allpanel=columnPanel.getComponents();  
					columnPanel.remove(allpanel.length-index);
					columnPanel.revalidate();  
					   validate();  
					    repaint();
				}
			});
////////////////////////////////////////////////////////////////////////////////////////////////
			
		    JButton btnAdd = new JButton("Add");
			btnAdd.setBounds(241, 3, 65, 18);
			rowPanel.add(btnAdd);
 
			btnAdd.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent ev) {
					addRow();
					Container d=( (JButton) ev.getSource()).getParent();
 
						int index=0;
					 Iterator<JPanel> itr = listRowPanel.iterator();
					    while (itr.hasNext()) {
					      JPanel element = itr.next();
					      	if (element.equals(d))
					      		{
					      		//System.out.println(element+" true" );
					      		System.out.println( index );
					      		}
					      	else
					      		{
					      		//System.out.println(element+" false" );
					      		}
					      	index++;	
					    }
	 
				}
			});

			nbrows++;

			listRowPanel.add(rowPanel);
			 columnPanel.add(rowPanel);
			    columnPanel.validate();
			    columnPanel.repaint();
	  }
///////////////////////////////////////////////////////////////////////////////////////////
		    
		   
	  void addRow2(JPanel rowPanel, int index)
	  {
		   
		for( int i = 0;i<index;i++)
			{ 
				   listRowPanel.add(rowPanel);
			}
	  }
	  
	  void deletRow(/*the index*/)
	  {
		   
	  }
	  
	  void sourceParent(ActionEvent ce)
	  {
		  Object object = ce.getSource();
		  JButton button = (JButton)object;
		  Container container = button.getParent();
		  System.out.println(container);

	  }
}
I removed from this code the previous changment in the last post, exactly of btnAdd and btnDel ActionPerformed....



This is the code that I added after AddRow invocation:
I removed from the addButton actionPerformed because it needs more changments ..
Could you please give me some suggestions??
Java Code:
btnAdd.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent ev) {
					addRow();
					Container d=( (JButton) ev.getSource()).getParent();
 
						int index=0;
					 Iterator<JPanel> itr = listRowPanel.iterator();
					    while (itr.hasNext()) 
					    {
					      JPanel element = itr.next();
					      	if (element.equals(d))
					      		{
					      		//System.out.println(element+" true" );
					      		System.out.println("index off Add : "+ index );
					      		}
					      	index++;	 
					    }
					    
					  int nbAllPanel=columnPanel.getComponentCount();
					  Component[]allpanel=columnPanel.getComponents();  
					  columnPanel.removeAll();
					  int index2=0;
					  
					  while(index2<nbAllPanel)
					  {
						  if(index2==index)
						  {
							//  columnPanel.add(btnAdd);
						  }
						  else
						  {
							  columnPanel.add(allpanel[index2]);
						  }
							  
					  }
					    
					   
	 
				}
			});


This is the delete button code:
Java Code:
btnDel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent ev) {
					int index=0;
					Container d=( (JButton) ev.getSource()).getParent();
					 Iterator<JPanel> itr = listRowPanel.iterator();
					    while (itr.hasNext()) 
					    {
					      JPanel element = itr.next();
					      	if (element.equals(d))
					      		{
					      		//System.out.println(element+" true" );
					      		System.out.println("index of del : "+ index );
					      		}
					      	index++;	 
					    }
					Component[]allpanel=columnPanel.getComponents();  
					columnPanel.remove(allpanel.length-index);
					columnPanel.revalidate();  
					   validate();  
					    repaint();
				}
			});