我如何摆脱Jframe底部的这条灰线
我正在尝试使用多个jpanels创建一个40x40网格,然后在设法创建它之后,jframe的底部有一个空的空间。
public drawBoard() {
createMap(40, 40);
}
public void createMap(int maxX, int maxY) {
String [ ][ ] map = new String [maxX][maxY];
//create 40 panel for the snake to move around in
for (int i=1; i < maxX; i++) {
for (int j=1; j < maxY; j++) {
JPanel panel = new JPanel();
add(panel);
panel.setPreferredSize(pref_size);
String name = String.format("[%d, %d]", i, j);
setLayout(new GridLayout(maxX, maxY, 1, 1)); //change gap to 0 after tests are done
setBackground(Color.GRAY);
panel.setName(name);
}
}
}
private static void createFrame() {
JFrame frame = new JFrame("Snake");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new drawBoard());
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setResizable(false);
};
I am trying to create a 40x40 grid using multiple JPanels and after I managed to create it, there is this empty space at the bottom of the JFrame.
public drawBoard() {
createMap(40, 40);
}
public void createMap(int maxX, int maxY) {
String [ ][ ] map = new String [maxX][maxY];
//create 40 panel for the snake to move around in
for (int i=1; i < maxX; i++) {
for (int j=1; j < maxY; j++) {
JPanel panel = new JPanel();
add(panel);
panel.setPreferredSize(pref_size);
String name = String.format("[%d, %d]", i, j);
setLayout(new GridLayout(maxX, maxY, 1, 1)); //change gap to 0 after tests are done
setBackground(Color.GRAY);
panel.setName(name);
}
}
}
private static void createFrame() {
JFrame frame = new JFrame("Snake");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new drawBoard());
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setResizable(false);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到一个答案,看起来是39x39网格而不是40x40,一旦更改了网格,就没有空白。都很好
Found an answer, looks like it was a 39x39 grid instead of 40x40, once changed the grid just fell into place with no blank spaces.all good