title: Counting character occurrences in a String (frequency)
body: <p>I have this GUI that counts the occurances of the first letter in a string.  I would like it to count all letters in column format like:</p>
  
  <p><img src="https://i.stack.imgur.com/B7l84.png" alt="enter image description here"></p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.event.ActionEvent;  
  import java.awt.event.ActionListener;  
  import javax.swing.JButton;  
  import javax.swing.JFrame;  
  import javax.swing.JLabel;  
  import javax.swing.JPanel;  
  import javax.swing.JTabbedPane;  
  import javax.swing.JTextField;  
  public class Index2 extends JFrame implements ActionListener  
  {  
      private JTabbedPane jtabbedPane;  
      private JPanel characterFinder;  
      JTextField enterText, countText;  
  
      public Index2()  
      {  
          setSize(400, 250);  
          setVisible(true);  
          setSize(400, 250);  
          setVisible(true);  
          setTitle("Total Characters");  
          setSize(300, 200);  
          JPanel topPanel = new JPanel();  
          topPanel.setLayout(new BorderLayout());  
          getContentPane().add(topPanel);  
          createCharacterFinder();  
          jtabbedPane = new JTabbedPane();  
          jtabbedPane.addTab("Count Characters", characterFinder); 
          topPanel.add(jtabbedPane, BorderLayout.CENTER);  
      }
      public void createCharacterFinder()  
      {  
          characterFinder = new JPanel();  
          characterFinder.setLayout(null); 
          JLabel enterLabel = new JLabel(  
                  "Enter Some Text");  
          enterLabel.setBounds(90, 5, 260, 20);  
          characterFinder.add(enterLabel); 
          enterText = new JTextField();  
          enterText.setBounds(10, 30, 270, 70);  
          characterFinder.add(enterText);  
  
          JButton search = new JButton("Count Occurences of Each Letter");  
          search.setBounds(15, 100, 260, 20);  
          search.addActionListener(this);  
          characterFinder.add(search);
  
          countText = new JTextField();  
          countText.setBounds(80, 130, 120, 500);  
          characterFinder.add(countText);
      }
          public void actionPerformed(ActionEvent e){
              String st=enterText.getText();
              char searchedChar=enterText.getText().charAt(0);
              count(searchedChar,st);
      }
      public int count(char c, String str) {
          if (str == null) return 0;
          int cnt = 0;
          for (int i = 0;; cnt++) {
          if ((i = str.indexOf(c,i)+1) == 0) break;
          }
          countText.setText("Character "+c+" occurs "+cnt+" times");
          return cnt;
          }
  
      public static void main(String[] args)  
      {  
          JFrame frame = new Index2();  
          frame.setSize(300, 700);  
          frame.setVisible(true);  
      }  
  }
  </code></pre>