Having lost focus on the JPanel screen while swinging, the contents are not displayed on the screen

I am using JTabbedPane with JPanel to display JTable on one tab and text, drop down menu and jbutton on another tab.

The first time it works fine, but if I hide or switch the screen to another application and return to my application, it will display the data correctly, but with a serious problem with changing tabs in JTabbedPane. Now the tabs screen turns blue and does not display data. (I hope that there is data, but they do not repaint or update the full window).

Now with the blue screen, I am doing the same procedure and tab changes in JTabbedPane, it shows the correct data.

I used redrawing, but it doesn't work.

Help needed to properly update a window or tab.

+3
source share
1 answer

Make sure you make all changes to Swing components (including changing data in models or manually enabling tabs) through Event Dispatch Thread. Swing allows the developer to ignore thread safety, but this creates undefined behavior.

Here is an example of modifying the contents of a JComboBox model.

final DefaultComboBoxModel model = (DefaultComboBoxModel) comboBox.getModel();
EventQueue.invokeLater(new Runnable(){
    public void run(){
        // Add all Swing component modification code here..
        // The line of code below is but an example of what you could do
        model.addElement("String element");
    }
});
+3
source

All Articles