else if(e.getSource()==button3){
JButton[] addSong = new JButton[50];
JLabel[] label = new JLabel[50];
JPanel[] smallPanel = new JPanel[50];
JPanel panel = new JPanel(new GridLayout(1,50));
for(int i=0;i<50;i++){
addSong[i] = new JButton("+"); // creates a new button with text "+"
label[i] = new JLabel("Name of song"); // creates a new JLabel with text "Name of song"
smallPanel[i] = new JPanel();
smallPanel[i].add(addSong[i]);
smallPanel[i].add(label[i]);
panel.add(smallPanel[i]);
}
tabs.addTab("All Songs",panel);
}
the reason of this behavior is because by default in an Array of Object (that you created with Type[], where Type is one of JPanel, JButton and JLabel) all records are indeed Objects, but null.
That means that you are telling java "hey, in this array go only this Object", Java knows that only "Object" type can go inside its "spaces" but don't know what kind of objects.
This is the reason why for each "space" in the array (looped with the for cycle) you have to tell Java "here go a new JButton" (or JPanel, or JLabel). And this is the way:
arrayName[index] = new Type();