I have got this piece of code:
frame.setTitle("SideScroller");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
Dimension dim = new Dimension(1000, 500);
frame.setContentPane(gamePanel); //gamePanel is an extended JPanel
gamePanel.setPreferredSize(dim);
frame.pack();
After I run this code and fill the gamePanel
with parts of 50x50p, which should fill the gamePanel
and thus the frame
completely, there are some empty rows of pixels at the right and bottom of the screen.
frame.getSize(); //gives us: 1016 x 539
frame.getInsets(); //gives: Top: 31 | Left: 8 | Bottom: 8 | Right: 8
An image of the result:
As you can see, there is still some empty room in the JFrame
.
The code to fill the gamePanel
:
//Fill the panel with landscape
//One part : 50x50 px
//Panel : 1000x500 px
//Width : 20 prts
//Height : 10 prts
@Override
public void paint(Graphics g){
super.paint(g);
for(int i = 0; i < 20; i++){
for(int j = 0; j < 10; j++){
//Decide which landscape-img should be used
switch(levelOne[j][i]){
case 0:g.drawImage(new ImageIcon("resources\\landscape-img\\air.png")
.getImage(), 50 * i, 50 * j, null);
break;
case 1:g.drawImage(new ImageIcon("resources\\landscape-img\\ground.png")
.getImage(), 50 * i, 50 * j, null);
break;
}
}
}
g.dispose();
}
I do not see why the frame
isn't filled fully. Hope someone can help me!