Answer the question
In order to leave comments, you need to log in
How to get rid of flickering when opening Java window?
The opening frame gets annoying with its flickering when centered. Here is the code for a simple program.
Main.java
import javax.swing.*;
public class Main extends JFrame {
public static void main(String[] args) {
JFrame frame = new JFrame("Тест фрейма");
frame.add(new MainMenu());
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null); //из-за него мерцает???
}
Answer the question
In order to leave comments, you need to log in
The main mistake is that all your code needs to be wrapped:
SwingUtilities.invokeLater(new Runnable() {
// TODO
})
And you can try setDoubleBuffered(true);
But, of course, you need to launch the window in the interface processing thread.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question