How to automatically adjust a JFrame to screen size?

1

I have a program and when I run on different computers the window gets completely undone and you can not see the components you have in Jframe, I would like to know if there is any way the window can be automatically adjusted to the screen of that computer in a way to keep the components in their place

    
asked by anonymous 08.11.2014 / 23:07

2 answers

3

Try to do this

Toolkit kit = Toolkit.getDefaultToolkit();  
Dimension tamTela = kit.getScreenSize();  

//Pega largura e altura da tela 
int larg = tamTela.width;  
int alt = tamTela.height;  

/* larg x 0.7; para ocupar 70% da tela por exemplo  */  
/* alt x 0.7;*/  

//Manda o JFrame utilizar suas dimensões  
setSize(larg,alt); 
    
08.11.2014 / 23:18
1

Place no initializeComponents ()

    setResizable(false);
    setLocationRelativeTo(null);
    pegarResolucao();     

Create this function

private void pegarResolucao() {
        Toolkit t = Toolkit.getDefaultToolkit();
        Dimension dimensao = t.getScreenSize();
        this.setSize((dimensao.width + 5), (dimensao.height - 38));

 }
    
03.06.2016 / 18:46