title: display my output in a matrix form
body: <p><img src="https://i.stack.imgur.com/cOXPw.png" alt="my application-sequence alignment"></p>
  
  <p>Above is the image of my application.i am build an application to do the alignment of two string.the two string will be compared and a 2d array will be populated.the values of the 2d array will be the values of the matrix.All works perfectly fine the only prob i ma having is that i want when it print the values of the matrix it prints it in a matrix format as it the example below instead of having an output of "0000000011011000002100013" i want it to display as this</p>
  
  <pre><code>   0 0 0 0 0
     0 0 1 0 0
     0 0 1 0 0
     0 1 0 2 1
     0 1 0 1 3
  </code></pre>
  
  <p>When print out it has to see if the number of character printed is equal to my row size and then move to next line and continues to print until all matrix values has been displayed.Below are my pieces of my codes.thank you in advance</p>
  
  <p>Code for my Compute matrix button</p>
  
  <pre><code>        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)        {                                         
     match_reward = Integer.parseInt (match_tf.getText());
     mismatch_penalty =Integer.parseInt (mismatch_tf.getText());
     gap_cost=Integer.parseInt(gap_tf.getText());
     build_matrix();
     collumn_tf.setText(String.valueOf(max_col));
     row_tf.setText(String.valueOf(max_row));
     highest_score_tf.setText(String.valueOf(max_score));
    StringBuilder sb = new StringBuilder();
    for (int i =0; i &lt; rows; i++) {
     for (int j = 0; j &lt; cols; j++) {
  
            sb.append(String.valueOf(matrix[i][j]));
      sb.append(' ');
      }
  }
   matrix_tf.setText(sb.toString());
  }                         
  </code></pre>
  
  <p>Code to build my matrix</p>
  
  <pre><code>     private void build_matrix() {
      String seq1 = sequence1_tf.getText();
      String seq2 = sequence2_tf.getText();
  
  
  
      int r, c, ins, sub, del;
  
      rows = seq1.length();
      cols = seq2.length();
  
      matrix = new int [rows][cols];
  
      // initiate first row
      for (c = 0; c &lt; cols; c++)
          matrix[0][c] = 0;
  
      // keep track of the maximum score
      max_row = max_col = max_score = 0;
  
      // calculates the similarity matrix (row-wise)
      for (r = 1; r &lt; rows; r++)
      {
          // initiate first column
          matrix[r][0] = 0;
  
          for (c = 1; c &lt; cols; c++)
          {
                          sub = matrix[r-1][c-1] +     scoreSubstitution(seq1.charAt(r),seq2.charAt(c));
                          ins = matrix[r][c-1] + scoreInsertion(seq2.charAt(c));
                          del = matrix[r-1][c] + scoreDeletion(seq1.charAt(r));
  
              // choose the greatest
              matrix[r][c] = max (ins, sub, del, 0);
  
              if (matrix[r][c] &gt; max_score)
              {
                  // keep track of the maximum score
                  max_score = matrix[r][c];
                  max_row = r; max_col = c;
  
              }
  
  
          }
      }
  
  }
  </code></pre>