0

I have a problem of size ... because I set my Jpanel and JFrame with specific size but when I draw the image is like if the window have a different size :

public GameView(){
    //System.out.println("hey");
    JFrame container= new JFrame("Loderunner");
    JPanel panel= (JPanel) container.getContentPane();
    panel.setPreferredSize(new Dimension(115,115));
    panel.setMinimumSize(new Dimension(115,115));
    panel.setLayout(null);
    setBounds(0,0,115,115);
    panel.add(this);
    setIgnoreRepaint(true);
    //requestFocus();
    //addKeyListener(new KeyHandle());
    //container.addKeyListener(new KeyHandle());
    requestFocus();
    container.setResizable(false);
    container.pack();
    container.setVisible(true);
    container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    createBufferStrategy(2);
    strategy=getBufferStrategy();
    loadLevel("livel.txt");
}

Here's an image of my problem:

enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2695795
  • 21
  • 1
  • 2
  • For better help sooner, post an [SSCCE](http://sscce.org/). But in general, set a preferred size on the panel then pack the frame. – Andrew Thompson Sep 02 '13 at 10:27
  • In this link there is a folder in which there are file .java e image ... you could compile the files and run the main file http://ge.tt/6aRQzsq/v/0?c – user2695795 Sep 02 '13 at 13:22
  • At no point did I ask for, or suggest you supply, an image. **Read the link.** As it happens, an image for an SSCCE can be generated in a single line of code. – Andrew Thompson Sep 02 '13 at 13:35
  • 1
    Oh sorry , I don't know how do all this things , so thank you anyway.... – user2695795 Sep 02 '13 at 13:53

1 Answers1

2

The main problem here is that 115px width is not going to fill the minimum width of the frame with decorations. Instead do one of:

  1. Widen the rendering
  2. Live with a border
  3. Remove the frame decorations or..
  4. Use a window instead
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • In this link there is a folder in which there are file .java e image ... you could compile the files and run the main file ge.tt/6aRQzsq/v/0?c – user2695795 Sep 02 '13 at 13:23
  • 1
    @user2695795: Please edit your question to include an [sscce](http://sscce.org/) that exhibits the problem you describe. In your [sscce](http://sscce.org/), access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513); use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513); or use `UIManager` icons, as shown [here](http://stackoverflow.com/a/12228640/230513). – trashgod Sep 02 '13 at 13:40