Jdesktoppane does not remove closed screen rendering, how to proceed?

Asked

Viewed 97 times

1

I created a basic screen with Netbeans that has a menu and a JDesktopPane that opens the JInternalFrame menu-referenced:

screenshot da tela sem o bug

As well as a function to open these JInternalFrame:

private void openView(JInternalFrame view){
    // o "frameInterno" referencia o JDesktopPane
    this.frameInterno.removeAll();
    this.frameInterno.add(view);
    view.setVisible(true);
}

private void itemClienteActionPerformed(java.awt.event.ActionEvent evt) {                                                
    this.openView(new ClienteView());
}

However, if I try to open another screen with the same function, the screen continues with the image of the previous rendering recorded in the background:

tela do sistema com o bug

I’m wearing the Look and Feel JTattoo, but even using Nimbus or default the problem persists.

What could be causing this failure? How can I resolve?

System settings:

Kubuntu 18.04 LTS Openjdk 1.8

Repository on Github

1 answer

2


The issue that I think is at stake here is that you are not calling for a method to redesign the Panel. This is quite common while working with Guis in Java. There are methods for each GUI that solve this problem, for example:

in swing we have this thread: https://stackoverflow.com/questions/9347076/how-to-remove-all-components-from-a-jframe-in-java

Just in this thread, the community has done several different ways.

private void openView(JInternalFrame view){
    // o "frameInterno" referencia o JDesktopPane
    this.frameInterno.removeAll();
    //Tente algo nessas linhas para começo de conversa
    this.PanelPrincipal.repaint();
    revalidate();
    validate(); 
    this.revalidate();
    this.validate()
    //Além disso, sugiro inverter a ordem abaixo: primeiro deixar visivel e depois adicionar ao Frame.
    this.frameInterno.add(view);
    view.setVisible(true);
}

Some extra tips to help code level (work-arounds):

  1. You can create a routine, which traverses within a for Frame per Frame (except Main) and executes the X action content of these Frames.

  2. In case you noticed that the routine you posted here only works for more than 2 Frames opened, then it can be something related to the lack of a reserved word that gives a "refresh" in the frames.

  3. You can create a Manager method, which keeps checking Events (more or less what I described in 1) from within the main function synchronously or you can implement threads that check this from time to time with an aid of mutex or semaphore.

With the limitation I have of the topic, without knowing your project, this is what I can offer you. Good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.