我的refresh和refresh2方法導致出現一個新的窗口jpanel。我希望我的textareas能夠在同一個窗口中更新。我不認爲我在調用正確的jpanel。我該如何解決?另外爲什麼它會創建一個新窗口?java gui textarea沒有正確更新
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);
}
請發表您的完整源代碼。你提供的東西根本不調用'refresh'方法 – mbatchkarov 2012-02-08 18:02:53