java - Get the real size of a JFrame content (NEW) -


i writing game in java, , don't want use layout manager jframe. class extends jframe, , looks this:

//class field static jpanel contentpane;  //in class constructor this.contentpane = new jpanel(); this.contentpane.setlayout(null); this.setcontentpane(contentpane); 

i want jpanel 600x600 px, when set size of jframe calling this.setsize(600,600) method, jpanel size less 600x600 px because border of jframe window included too.

how can set size of jpanel 600x600 px?

p.s. have seen of previous post , none of them work me. example: get real size of jframe content not work me. else can do?

how can set size of jpanel 600x600 px?

override getpreferredsize() method of custom game panel return size want panel be.

@override dimension getpreferredsize() {     return new dimension(600, 600); } 

then basic code create frame be:

gamepanel panel = new gamepanel(); frame.add(panel, borderlayout.center); frame.pack(); frame.setvisible(true); 

now game logic contained in gamepanel class.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -