title: Insert text to selected JTextfield using JButtons
body: <p>I have multiple text fields and buttons</p>
  
  <p><img src="https://i.stack.imgur.com/1iLjV.jpg" alt="Textfields">
  <img src="https://i.stack.imgur.com/2vD4L.jpg" alt="buttons"></p>
  
  <p>When a text field is selected, text should be added to it when a button is pressed.</p>
  
  <p>This is how I tried </p>
  
  <pre><code>import javax.swing.text.JTextComponent;
      private void num9ActionPerformed(java.awt.event.ActionEvent evt) {                                            
              JTextComponent component = getFocuedComponent();
              component.setText( component.getText() + "9" );
  
      }
  </code></pre>
  
  <p>But it didn't work for me.</p>
  
  <p>PS. Trying to make Matrix Calculator.</p>
  
  <p><strong>EDIT :</strong> for reference ... 
  this how i implemented it ... after SJuan76's answer .... thanks!!</p>
  
  <pre><code>private JTextComponent selectedTextField;
  
  // TextFields onFocus event
      private void a33FocusGained(java.awt.event.FocusEvent evt) {
          selectedTextField = (JTextComponent) evt.getSource();
      }
  // action for button
          private void num9ActionPerformed(java.awt.event.ActionEvent evt) {                                            
                  selectedTextField.setText( selectedTextField.getText() + "9" );
  
          }
  </code></pre>