【发布时间】:2014-12-22 14:13:38
【问题描述】:
我有两个 JFrame A 和 B。B 有一个 textArea。我想在 B 中的 TextArea 中添加一些文本 单击 A 中的按钮。这是我的代码:
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 是 B 类的对象
- textArea 是 B 类中的 JTextArea 变量名
【问题讨论】:
-
在向 JTextArea 添加文本后尝试在
b中调用repaint() -
不要重绘任何东西,以获得更好的帮助,尽快发布一个简短、可运行、可编译的 SSCCE/MCVE
-
你可以使用 b.textArea.append("your text");
-
你的 textArea 是公开的吗?
-
你能解释一下你的答案吗
标签: java swing button jframe textarea