java gui textarea 未正确更新
我的刷新和刷新2方法导致出现一个新窗口jpanel。我希望我的文本区域在同一窗口中更新。我认为我没有调用正确的 jpanel。我该如何解决这个问题?另外为什么它要创建一个新窗口?
public static void main(String[] args) {
MPUComp frame = new MPUComp();
frame.setVisible(true);
}
public MPUComp() {
setTitle("Mpu Finder");
ImageIcon LoadIco = new ImageIcon(getClass().getResource("load.png"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 799, 680);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnFind1.setBounds(250, 27, 68, 23);
contentPane.add(btnFind1);
btnLoadMpu.setBounds(328, 27, 36, 22);
btnLoadMpu.setIcon(LoadIco);
contentPane.add(btnLoadMpu);
btnFind2.setBounds(642, 27, 68, 23);
contentPane.add(btnFind2);
btnLoadMpu2.setBounds(720, 28, 36, 22);
btnLoadMpu2.setIcon(LoadIco);
contentPane.add(btnLoadMpu2);
menu();
}
public void refresh(String pane1) {
textArea_1.append(pane1 + "\n");
contentPane.revalidate();
contentPane.repaint();
setVisible(true);
}
public void refresh2(String pane1) {
textArea_2.append(pane1 + "\n");
contentPane.revalidate();
contentPane.repaint();
setVisible(true);
}
My refresh and refresh2 methods cause a new window jpanel to appear. I want my textareas to update in the same window. I don't think I am calling the right jpanel. How do I fix this? Also why is it creating a new window?
public static void main(String[] args) {
MPUComp frame = new MPUComp();
frame.setVisible(true);
}
public MPUComp() {
setTitle("Mpu Finder");
ImageIcon LoadIco = new ImageIcon(getClass().getResource("load.png"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 799, 680);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnFind1.setBounds(250, 27, 68, 23);
contentPane.add(btnFind1);
btnLoadMpu.setBounds(328, 27, 36, 22);
btnLoadMpu.setIcon(LoadIco);
contentPane.add(btnLoadMpu);
btnFind2.setBounds(642, 27, 68, 23);
contentPane.add(btnFind2);
btnLoadMpu2.setBounds(720, 28, 36, 22);
btnLoadMpu2.setIcon(LoadIco);
contentPane.add(btnLoadMpu2);
menu();
}
public void refresh(String pane1) {
textArea_1.append(pane1 + "\n");
contentPane.revalidate();
contentPane.repaint();
setVisible(true);
}
public void refresh2(String pane1) {
textArea_2.append(pane1 + "\n");
contentPane.revalidate();
contentPane.repaint();
setVisible(true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样的问题被问到近50一天几次。下次,请搜索已经得到充分回答的相关项目。
有关详细信息,请参阅Swing 中的并发。
Questions like these are asked almost 50 times a day. Next time, please do a search for related items that have already been sufficiently answered.
For more information, see Concurrency in Swing.