0

I'm working on a checkers board in java. But I have a strange problem: Eventough I set the vgap at 0 it still creates a vgap. There is a space of aprox 5px between the squares in height. The width is alright. This is my layout code of the Diagram object:

this.setLayout(new GridLayout(10, 10, 0, 0));
this.setPreferredSize(new Dimension(230, 230));

And this is where I implement the Diagram:

// The jpanel that has to contain the diagram
jpanel.setLayout(new FlowLayout());
add(jpanel, BorderLayout.WEST);
// The placement of the diagram in that jpanel
jp.add(new diagram());

This is how it looks:

[][][][][][][][][]
<The spacing that I have to get removed>
[][][][][][][][][]

But it should be like:

[][][][][][][][][]
[][][][][][][][][]

^
|
no spacing between them
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Bram
  • 91
  • 1
  • 8
  • 1
    My guess is whatever you put in the container that is put in each grid cell is not high enough. Please post a full example which reproduces your problem – stryba Aug 14 '12 at 21:53
  • I found the reason of the problem its the image inside the JLabel thats not shown for 100% height but less. How do I modify the height of an imageIcon? – Bram Aug 14 '12 at 22:10

2 Answers2

3
  • you have to change LayoutManager for JPanel from FlowLayout to the BorderLayout or ...,

  • FlowLayout pretty accepting PreferredSize came from layed JCompoments into container (JPanel), everything depends of

    1. Diagram returns PreferredSize

    2. if and how could be resizable Diagram with container

    3. how and where is really used GridLayout

  • for better help sooner post an SSCCE

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Could be `JPanel` UI delegate, too; no problem using `new JLabel(new ImageIcon())`, seen [here](http://stackoverflow.com/a/3078354/230513). – trashgod Aug 14 '12 at 23:42
0

I fixed the issue by loading the image into the JPanel instead of a JLabel I made the image into a BufferedImage then draw it onto the JPanel with drawImage

Bram
  • 91
  • 1
  • 8