3
I wanted to know how to call a Secondary Window in Swing and leave it centered with the Main Window of the program. At the moment, when I call him appears in the upper left corner.
3
I wanted to know how to call a Secondary Window in Swing and leave it centered with the Main Window of the program. At the moment, when I call him appears in the upper left corner.
4
Try it this way:
frame.setLocationRelativeTo(null);
2
You can center a frame through the method setLocationRelativeTo().
Take this 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. Search (from a control+f) for the method setLocationRelativeTo.
Browser other questions tagged java swing awt
You are not signed in. Login or sign up in order to post.
Thank you very much man, it worked at first.
– MarlonJhow
For nothing :D. If the answer helped you mark it as correct so that you can help others with the same doubt.
– DiegoAugusto