I wanted to know how to do when to call a secondary window in Swing it left centered with the main window of the program. At the moment, when I call it it appears in the upper left corner.
I wanted to know how to do when to call a secondary window in Swing it left centered with the main window of the program. At the moment, when I call it it appears in the upper left corner.
Try this:
frame.setLocationRelativeTo(null);
You can center a frame by using the setLocationRelativeTo () method. Here's an example:
import javax.swing.JFrame;
public class MeuFRame {
public static void main(String[] args) {
JFrame janela = new JFrame("Frame vazio");
janela.setSize(300,200);
janela.setVisible(true);
janela.setLocationRelativeTo(null);
}
}
You can learn more at documentation java.Procure (from a control + f) by the setLocationRelativeTo method.