1

I'm new to Java Swing. I created the simple window.

public class Main {

    public static void main(String[] args) throws Exception{
        EventQueue.invokeLater(() -> {
            var frame = new JFrame("My window");
            frame.setSize(300, 200);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

            frame.setVisible(true);
        });
    }
}

Every time I run my app the screen on my mac blinks and becomes black for a half of the second. Then window appears.

Did I forget something to add to avoid this or something is wrong with my mac?

Vitalii
  • 10,091
  • 18
  • 83
  • 151
  • 1
    Short answer, no. Long answer is complicated. Part of the problem has to do with Apple and how it allows developers to access things like the accelerated hardware (see Apple vs Flash) and the optimised pipeline. For many years, Apple was providing the core implementation for Java, but things changed with the open sourcing of the API and the ongoing love/hate relationship between Apple and ... well, the rest of the world . You might consider using JavaFX instead, but I can't say if you'd get better performance or not, but it would be worth a try – MadProgrammer Dec 20 '18 at 21:17
  • The delay seems less noticeable with JavaFX; compare [this native `WebView`](https://stackoverflow.com/a/33824164/230513) and [this `WebView` embedded in a `JFrame`](https://stackoverflow.com/a/31576647/230513). – trashgod Dec 21 '18 at 12:28

1 Answers1

0

Best you can do, go to Energy Saver in System preferences and disable automatic card switching. It helped me to resolve same issue.

Alex Faster
  • 199
  • 10