我正在使用java中的跳棋板。 但我有一個奇怪的問題: 事情我將vgap設置爲0,它仍然會創建一個vgap。 高度方格之間有一個5px的空間。 寬度是可以的。 這是圖表對象的我的佈局代碼:Java gridlayout忽略間隙
this.setLayout(new GridLayout(10, 10, 0, 0));
this.setPreferredSize(new Dimension(230, 230));
而這正是我實現圖:
// 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());
這是它的外觀:
[][][][][][][][][]
<The spacing that I have to get removed>
[][][][][][][][][]
但應如:
[][][][][][][][][]
[][][][][][][][][]
^
|
no spacing between them
我的猜測是無論你放在每個網格單元中的容器是不夠高的。請發佈一個完整的例子,重現你的問題 – stryba 2012-08-14 21:53:36
我發現問題的原因是它內部的JLabel圖像沒有顯示100%的高度,但較少。我如何修改imageIcon的高度? – Bram 2012-08-14 22:10:19