How to automatically adjust a Jframe to the screen size?

Asked

Viewed 4,732 times

1

I have a program, and when I run on different computers, the window is all broken up and you can’t see the components you have in Jframe, I would like to know if there is any way that the window can be automatically adjusted to the screen of that computer so that the components remain in place

  • It will depend on how your layout is mounted. It’s a little difficult to answer your question without knowing exactly how this your code. Take a look at the link of the comment I left in the reply.

2 answers

3

Try to do that

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); 
  • I understand, but that’s not what I mean, because I want the show to be on the screen

  • The screen wouldn’t be the whole screen?

  • It is to occupy the whole screen the only problem is that for example in the screens of the computers of my school are square and the jframe is formatted different and I wanted it to always be the same (adjusted automaticamnete)

  • 2

    There I understood, I thought I wanted to make it full automatically on any screen. Because this code does this. But your problem seems to be with the positioning of the components inside it right.

  • exact for example my laptop monitor where I did the program and larger than the school so some components disappear, know some way to do what I wish?

  • I will see if I find and pass you ok. I used few times jframes.

  • could send me the site with this information ?

  • I am looking for, go searching there for Gridbaglayout, read this http://javafree.uol.com.br/topic-5792-Tudo-sobreo-GridBagLayout.html

  • Take a look at this: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html The solution is probably a composition of several of these layout managers

Show 4 more comments

1

Put on initializeComponents()

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

and creates that function

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

 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.