private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    	int targetLayer;
    	String propFunc;
    	String actFunc;
    	double[] actParam = new double[5];
    	try{
        	//throws NumberFormatException if not a Number.
    		targetLayer = Integer.parseInt(whichLayerTextField.getText())-1;
    		//throws NullPointerException if Network has not been initialized.
    		if (targetLayer < myNetwork.getLayerCount() && targetLayer >= 0){
    			
    			//adding a new Neuron might change the maxLayerSize to maxLayerSize + 1
    			propFunc = possiblePropFunc[propagationComboBox.getSelectedIndex()];
    			actFunc = possibleActFunc[activationComboBox.getSelectedIndex()];
    			//TODO add check for numberformat
    			actParam[0] = Double.parseDouble(actParamTextField.getText());
                myNetwork.addNeuron(targetLayer, new Neuron(propFunc,actFunc,actParam));
                
                //Check if the maxLayerSize has changed and if so add a column to the gridlayout.
                int whereTo;
                if (myNetwork.maxLayerSize()> gridPanelLayout.getColumns()){
                	int newColumns = gridPanelLayout.getColumns()+1;
                	gridPanelLayout.setColumns(newColumns);            
                	//fill up the gridLayout with the new Neuron and empty labels where there are no new Neurons to be added.
                	for (int row = 0; row < myNetwork.getLayerCount();row++){
                		if (row == targetLayer){
                			//we want to put the Neuron behind the last existing one in a row.
                			whereTo = newColumns*row-1 + myNetwork.howManyInLayer(row);
                			gridPanel.add(new NeuronButton("" + 0,targetLayer,myNetwork.howManyInLayer(targetLayer)-1,this),whereTo);
                		} else {
                			// we need to add a label to the end of each row. if we have a gridlayout with 3 rows and 5 columns
                			// this means: add a label to index 4,9 and 14. this can be calculated by rowNumber*Columns-1 i.e for column 2: 3*2-1 = 9.
                			whereTo = newColumns*row-1 + newColumns;
                			gridPanel.add(new JLabel(""),whereTo);
                		}                		
                	}
                //If the maxLayerSize has not been changed, a Label has to be replaced by the added Neuron.
                } else {
                	whereTo = gridPanelLayout.getColumns()*targetLayer-1 + myNetwork.howManyInLayer(targetLayer);
                	gridPanel.remove(whereTo);
                	gridPanel.add(new NeuronButton("" + 0,targetLayer,myNetwork.howManyInLayer(targetLayer)-1,this),whereTo);
                }
                
              //Calculate new Height and Width of gridPanel
                int width = (neuronWidth[currentZoom]+gridHspace)*gridPanelLayout.getColumns()-gridHspace;
                int height = (neuronHeight[currentZoom]+gridVspace)*gridPanelLayout.getRows()-gridVspace;
                gridPanel.setPreferredSize(new Dimension(width,height));
                drawPanel.setPreferredSize(new Dimension(width,height));
                gridPanel.setVisible(false);
                gridPanel.setVisible(true);
    		} else {
    			JOptionPane.showMessageDialog(this, "The layer can only be between 1 and " + (myNetwork.getLayerCount()));
    		}   
        }  catch (NumberFormatException e){
        	JOptionPane.showMessageDialog(this, whichLayerTextField.getText() + " is not a valid layer");
        }  catch(NullPointerException e){
        	JOptionPane.showMessageDialog(this, "Please setup a Network first.");
        }
    }//GEN-LAST:event_addButtonActionPerformed