Hi!
I'm trying to load an ArrayList with jbuttons .... when explicitly added like this , it works fine......
package AddRFSwitchPac;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JButton;
/**
*
* @author Richard
*/
public class ButtonArrayList {
/**
* Creates a new instance of ButtonArrayList
*/
public ButtonArrayList() {
ArrayList<JButton> buttons = new ArrayList<JButton>();
buttons.add(AddRFSwitchMain.jButton1);
buttons.add(AddRFSwitchMain.jButton2);
buttons.add(AddRFSwitchMain.jButton3);
buttons.add(AddRFSwitchMain.jButton4);
buttons.add(AddRFSwitchMain.jButton5);
JButton button = (JButton)buttons.get(3);
if (button != null)
button.setBackground(new Color(0,0,0));
}
}
.... but when I try to load the jButtons from a loop .... It will not work ...
package AddRFSwitchPac;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JButton;
/**
*
* @author Richard
*/
public class ButtonArrayListLoad {
/**
* Creates a new instance of ButtonArrayListLoad
*/
public ButtonArrayListLoad() {
int rc = AddRFSwitchMain.jTable1.getRowCount();//jTable is 5 rows ... this equates to 5 jButtons
ArrayList<JButton> buttons = new ArrayList<JButton>();
for(int i = 0; i <= rc; i++) {
String key = String.valueOf(i);
JButton button = new JButton();
// buttons.add("key");// this doesnt work as string "key" or an int (i)
}
// here I pick what button I want out of the Arraylist
JButton button = buttons.get(2);
if (button != null)
button.setBackground(new Color(0,0,0));
}
}