0

I have two JFrames A, and B. B has a textArea. I want to add some text to that TextArea in B by clicking a button in A. here is my code:

JButton btn = new JButton("Text");
btnButton_1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        b.textArea.setText("Button clicked");
    }
});
btnButton_1.setBounds(10, 45, 89, 23);
frmA.getContentPane().add(btnButton_1);
  • b is object of class B
  • textArea is JTextArea variable name in class B
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
user3417593
  • 33
  • 1
  • 7

1 Answers1

0

Use repaint() method of components.

JButton btn = new JButton("Text");
        btnButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                b.textArea.setText("Button clicked");
                b.frameB.repaint();
            }
        });
        btnButton_1.setBounds(10, 45, 89, 23);
        frmA.getContentPane().add(btnButton_1);
shepard23
  • 148
  • 2
  • 13