chinna_82
chinna_82

Reputation: 6403

Java Swing - GUI not refreshing or freeze after java 1.8 updates

I have a working application, which working fine in Java 1.6 and 1.7 and even 1.8 update 31. I just update my Java today 1.8 update 45 and found my application interface having issue. For an example: enter image description here This is my working application screen. This is what it should be, but after the update its become like this (below): enter image description here Once I get the not functioning interface, I need to click on the area or I need to minimize the application and open again to revert back to normal.

Code

frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
tab.setTabPlacement(2);
frame.add(tab, BorderLayout.SOUTH);
ComparePanelMin cmp = new ComparePanelMin();
tab.add("Compare", cmp);
ReportPanelMin rp = new ReportPanelMin();
tab.add("Reporting (For Single Compare)", rp);
ChangeListener changeListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent changeEvent) {
idx = tab.getSelectedIndex();
}

Above code to switch between the tabs. Any advice or reference links is highly appreciated. EDITED
DeadLock enter image description here

Upvotes: 0

Views: 1543

Answers (2)

Rahel Lüthy
Rahel Lüthy

Reputation: 7007

I have seen similar issues if not all Swing components are created on the event dispatch thread (EDT).

Make absolutely sure that even your initial JFrame is created/shown from the EDT:

  public class HelloWorldSwing {

    private static void createAndShowGUI() {
      JFrame frame = new JFrame("Hello Swing");

      // Your init code here...

      frame.setVisible(true);
    }

  public static void main(String[] args) {
    // Schedule creation of UI on the EDT
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          createAndShowGUI();
        }
    });
  }
}

Upvotes: 1

Sarfaraz Khan
Sarfaraz Khan

Reputation: 2186

I guess its an issue of deadlock I faced a similar issue of GUI freezing with Swing. Nothing worked out so I had to dig into the code of Swing and I found some really crappy codes which were causing the dead lock and it was very difficult to trace even in the thread dump. you can try these tools and check for dead lock http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jvisualvm.html

you can search how to identify dead lock using these tools

Also the way you're adding tab in frame is not the right way you should add it using frame.getContentPane().add(tab, BorderLayout.SOUTH)

Upvotes: 2

Related Questions