关于swing设置边框的问题

认真的coder 认真的coder 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有如下代码:

public class TestBorder extends JFrame{

public TestBorder()
{
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(9,9));
panel.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.blue));
JLabel label[] = new JLabel[81];
for(int i=0;i<label.length;i++)
{
label[i]=new JLabel(""+i);
label[i].setBorder(BorderFactory.createLineBorder(Color.red));
panel.add(label[i]);
}

this.add(panel);

this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setBounds(new Rectangle(245,345));
//this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
}

public static void main(String args[])
{
new TestBorder();
}

}

为什么panel的最右边还会有一些空白的区域呢?
运行结果为:
...全文
评论 3
收藏 已收藏
分享
返回顶部
认真的coder
Java SE 62,621 成员 307,251 内容