Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bottom and Right-Hand Unwanted Border  (Read 1360 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Posted 2012-08-28 05:20:07 »

I've encountered a problem that I've also seen in a few completed Java games

First off, I'm making an app using regular Java2D/Graphics2D setup

So my problem is that there's a border on the right hand side of my app and the bottom of my app
It's light grey
I don't know why it exists. My JFrame is the same dimensions of my Game and everything, but for some reason there's this region where nothing is drawn and it looks unprofessional

Has anyone else encountered this? How is it fixed?

Thanks
Offline GabrielBailey74
« Reply #1 - Posted 2012-08-28 05:25:09 »

Thinking it's the Frames ContentPane, it's default color is gray  Roll Eyes

You could add a new loop/Jpanel onto the Frames ContentPane, than paint it to blend as you wish.
- Or
1  
2  
JFrame frame = (JFrame) yourFrame;
frame.getContentPane().setBackground(java.awt.Color.black.darker());

Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Reply #2 - Posted 2012-08-28 05:53:11 »

Is there a way to get rid of the border? As in, I don't want to change the color, I just want to destroy the part of the frame that has none of the game drawn on it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GabrielBailey74
« Reply #3 - Posted 2012-08-28 05:57:38 »

Could you post some more details, don't know how exactly you're setup here.
JFrame >> ContentPane >> new JPanel with paint method?
JFrame >> Canvas?

Does your painting involve grabbing the JFrames dimensions?, know the getWidth()/getHeight() both change a little bit when frames switched from resizable to non resizable vise versa.

Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Reply #4 - Posted 2012-08-28 06:06:16 »

Sorry- I'm using a canvas and drawing a buffered image. This is what the class looks like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
public class GameComponent extends Canvas implements Runnable{
   private static final long serialVersionUID = 1L;
   
   private static final int WIDTH = 640;
   private static final int HEIGHT = 420;
   
   private BufferedImage bi;
   private Graphics graphics = null;
   private Graphics2D g2d = null;
   public BufferStrategy buffer;
   
   private boolean running;
   private Thread thread;
   Game game;

   public GameComponent () {
      Dimension size = new Dimension(WIDTH, HEIGHT);
      setSize(size);
      setPreferredSize(size);
      setMinimumSize(size);
      setMaximumSize(size);
     
      setIgnoreRepaint(true);
       
      game = new Game(WIDTH, HEIGHT);
   }

   public synchronized void start() {
      if (running) return;
      running = true;
      thread = new Thread(this);
      thread.start();
   }

   public synchronized void stop() {
      if (!running) return;
      running = false;
      try {
         thread.join();
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

   public void run() {
      //unimportant
   }
   
   public void draw(){
      g2d = bi.createGraphics();
     
      game.draw(g2d);
       
      graphics = buffer.getDrawGraphics();
      graphics.drawImage(bi, 0, 0, null);
           
           if(!buffer.contentsLost())
         buffer.show();
   }
   
   public void setUpBufferedImage(){
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice gd = ge.getDefaultScreenDevice();
       GraphicsConfiguration gc = gd.getDefaultConfiguration();
       
      bi = gc.createCompatibleImage(WIDTH,HEIGHT);

      createBufferStrategy(2);
      buffer = getBufferStrategy();
   }
   
   public static void main(String[] args) {
      GameComponent gameComponent = new GameComponent ();
      JFrame frame = new JFrame("Video Game");

      frame.setIgnoreRepaint(true);
      frame.add(gameComponent);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setResizable(false);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
     
      gameComponent.setUpBufferedImage();

      gameComponent.start();
   }
}
Offline GabrielBailey74
« Reply #5 - Posted 2012-08-28 06:11:44 »

(Ran the code, messed around a bit)
Has something to do within your Game class, thinking in your draw method since it's the only "visible" method being called upon while rendering.
Try messing around with your Dimensions by a few increments in the Game class yet?

Offline Screem
« Reply #6 - Posted 2012-08-28 06:22:22 »

I had this same problem too, and managed to fix it by subtracting 10 from my width and height when creating the dimension object.

Example:
1  
2  
Dimension size = new Dimension(g.WIDTH * g.SCALE - 10, g.HEIGHT * g.SCALE - 10);
g.setSize(size);


g refers to my Game class, which extends Canvas.

Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Reply #7 - Posted 2012-08-28 06:25:39 »

I had this same problem too, and managed to fix it by subtracting 10 from my width and height when creating the dimension object.

Example:
1  
2  
Dimension size = new Dimension(g.WIDTH * g.SCALE - 10, g.HEIGHT * g.SCALE - 10);
g.setSize(size);


g refers to my Game class, which extends Canvas.

Haha, that's silly but it does work. Kinda mysterious... Oh well. Thanks to everybody
Offline Screem
« Reply #8 - Posted 2012-08-28 06:51:26 »

Yeah, I don't quite understand it, but hey, it works! It doesn't even mess up where things are drawn, as in if your width is 350 and your height is 200, drawing at (349, 199) still renders at the bottom right corner.

Glad I could help. Smiley

Offline codeallergy

Innocent Bystander





« Reply #9 - Posted 2012-10-10 15:17:30 »

i got dat problem too. the best solution is to call setResizable(false) before adding a panel to the frame

example
1  
2  
3  
4  
5  
        this.frame = new JFrame(Game.TITLE);   
        this.frame.setResizable(false);
       
        JPanel panel = new JPanel(new BorderLayout());
        [...]    
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #10 - Posted 2012-10-10 15:53:05 »

i got dat problem too. the best solution is to call setResizable(false) before adding a panel to the frame

example
1  
2  
3  
4  
5  
        this.frame = new JFrame(Game.TITLE);   
        this.frame.setResizable(false);
       
        JPanel panel = new JPanel(new BorderLayout());
        [...]    

Yeah, I fiddled with the code a bit too. I found that if you just pack() after you do frame.setResizable(false) instead, the "borders" are gone.

- Jonas
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (40 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (67 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (57 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (44 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!