简体   繁体   中英

java gui textarea not updating properly

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);

}
  1. Swing components must be updated in the event-dispatching thread
  2. There is no need to invalidate the container or issue a repaint request
  3. Do not use a null layout manager
  4. When asking a question like this, it's best to include an sscce

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM