Вопрос

This is not a repeat question. Yes there are similar, but none have provided a working answer.

public class Tool extends JPanel implements ActionListener{

public JPanel Panel;

public Tool() {

}

public void show(){
    displayStuff();

          Panel.setVisible(true);
          revalidate();
          repaint();
    }
}

Tool MyTool = new Tool();
JPanel Master = new JPanel();
JPanel Dash = = new JPanel();
JTabbedPane Tabs = new JTabbedPane();
JTabbedPane Tabs.addTab("Dash", Dash);
JTabbedPane Tabs.addTab("Tool", MyTool.Panel);
Master.add(Tabs);

The real code is much more complex. But the basic issue is that when changes occurs on MyTool.Panel as a result of user pressing some buttons.

MyTool.Panel does NOT get repainted until I use mouse to move Master.

How can I force it to repaint?

Это было полезно?

Решение

Its not a perfect solution but you can validate and redraw the entire application, thats what I have done in the past. I've used something like

class MyPanel extends JPanel{
     public void doRedraw(){
         getTopLevelAncestor().revalidate();
         getTopLevelAncestor().repaint();
     }
}

Hope this helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top