JFrame no centro da tela[RESOLVIDO]

4 respostas
abelgomes

Boa tarde pessoal, consegui fazer meu JFrame ficar no meio da tela com umas dicas que vi aqui no forum, porem quando abro os JDialogs…eles vao la pra cima…alguma luz…to fazendo um projetinho SWing JPA+Hibernate…sao so 5 telas…alguma luz…só ta faltando isso…

4 Respostas

GabrielGarcia

Já tentou usar

JDialog.setLocationRelativeTo(null);
JDialog.setVisible(true);
abelgomes

já…e nao funcionou…
usei um codigo que centraliza a tela principal…ficou show de bola…mas as telas abertas em seguida vao la pra cima…e se eu usa r o mesmo cosido para centralizar ele fica mais abaixo do centro e mais a direita :s…

Rafael_Afonso

Veja se isso funciona:

// Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    
    // Determine the new location of the window
    int w = window.getSize().width;
    int h = window.getSize().height;
    int x = (dim.width-w)/2;
    int y = (dim.height-h)/2;
    
    // Move the window
    window.setLocation(x, y);

fonte: http://exampledepot.com/egs/java.awt/screen_CenterScreen.html

abelgomes

show de bola…funcionou…valews

Criado 16 de junho de 2009
Ultima resposta 17 de jun. de 2009
Respostas 4
Participantes 3