I'm making a dynamic table of JTextFields and JButtons. The list varies in length each time. Can I have an array of JButtons so that I know which of the buttons is pressed?

I tried it like this:
Code:
         JButton [] checkOut = new JButton();
         for (int i=0; i<allBooks.size(); ++i)
        {
        	currentBook = (Book)allBooks.get(i);
        	System.out.println(currentBook);

	final JTextField bookName = new JTextField(currentBook.toString());
	bookName.setEditable(false);
	contentPane.add(bookName);

	// if its not checked out adds check out button
	if (currentBook.checkedOutBy() == null)
	{
		checkOut[i].setLabel("Check Out");
		checkOut[i].addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		                if (currentCardholder != null)
	                {
currentBook.checkOut(currentCardholder);
			else
			Toolkit.getDefaultToolkit().beep();  // signal error
}
	                  });
		contentPane.add(checkOut[i]);
		
		setContentPane(contentPane);
                                pack();
		repaint();
	}
Sorry if thats hard to read! Or messed up!

NOMAD