So I have this problem. I have used StringBuilder and I am trying to create a display function using JOptionPane that will display a staff's name and pay. The display function also has to delete a line everytime a staff name is deleted from the system, as I do not want to have empty lines in my JOptionPane box. However, I cannot get it to display properly, as when I try to delete a staff name, it deletes it's own staff name, as well as all the staff names that are before it in the list. staffDetails is a separate array that i have containing the staff's name and pay.
here is my code for displaying staff: 

```
public static StringBuilder staffRecord= new StringBuilder();
  public static void displayrezStaffRecord(){
      int staffnumber=1;
      for (int n=0;n<staffDetails.length;n++){
          staffRecord.append(staffDetails[n].getStaffName());
          staffRecord.append("\t ");
          staffRecord.append(staffDetails[n].getPay());
          staffRecord.append(" \n ");
          staffnumber++;
          if (staffDetails[n].getStaffName()==null){
              menunumber--;
              staffRecord.delete(0,staffRecord.length());

          }

  }
      String finalresult= staffRecord.toString();
      JOptionPane.showMessageDialog(null,"Staff_No       Staff_Name      Pay      \n" +finalresult);
  } 
}

```