我不知道該如何居中。我試圖使用locationRelativeTo null,但gameBoard停留在左上角。 但我需要居中。如何在JFrame中居中對象
public static void main(String[] args) {
JFrame game = new JFrame();
game.setTitle("Game2048");
game.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
game.setSize(420, 700);
game.setResizable(false);
game.add(new Game2048());
// help here >>>> game.setLocation();
game.setVisible(true);
}
你想在JFrame中居中的對象還是要居中在屏幕上的JFrame? – bachph
只有我添加的對象。 –
可能的複製到[「如何設置JFrame的出現爲中心,不管顯示器分辨率的?」(https://stackoverflow.com/questions/2442599/how-to-set-jframe-to-appear-centered-regardless-的顯示器分辨率) –