java - JFrame setSize as screen size but minus titlebar -


i want have jframe size fits screen perfectly. used getscreensize(); resolution of computer , set jframe's size. found jframe's size bigger computer's resolution because of titlebar. (which mean u find bottom of jframe behind window taskbar)

the following code demostrate problem :

import java.awt.dimension; import java.awt.toolkit; import javax.swing.jframe;  public class titlebar extends jframe {      private final dimension _screensize = toolkit.getdefaulttoolkit().getscreensize();      public void run(){         this.settitle("titlebar");          this.setsize(_screensize);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.setvisible(true);     }       public static void main(string[] args) {         titlebar test = new titlebar();         test.run();     } } 

is possible set jframe size minus titlebar's size ?

two ways there: 1. "maximize" window using code i.e. add following:

this.setextendedstate( this.getextendedstate()|jframe.maximized_both ); 

your code this:

public class titlebar extends jframe {      private final dimension _screensize = toolkit.getdefaulttoolkit().getscreensize();      public void run(){         this.settitle("titlebar");          this.setsize(_screensize);         this.setextendedstate( this.getextendedstate()|jframe.maximized_both );         this.setdefaultcloseoperation(jframe.exit_on_close);         this.setvisible(true);     }       public static void main(string[] args) {         titlebar test = new titlebar();         test.run();     } } 

2. option workaround i.e. keeping @ top see on task bar i.e. adding following:

this.setalwaysontop(true); 

your code this:

public class titlebar extends jframe {      private final dimension _screensize = toolkit.getdefaulttoolkit().getscreensize();      public void run(){         this.settitle("titlebar");          this.setsize(_screensize);         this.setalwaysontop(true);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.setvisible(true);     }       public static void main(string[] args) {         titlebar test = new titlebar();         test.run();     } } 

depending upon need can choose option. believe option 1 you.