Swing JPanel 设置画布背景及自己绘图
时间:2014-08-12 22:11:45
收藏:0
阅读:983
构造器中添加
setBackground(Color.WHITE);
重新画图中添加
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// 转换画笔为2D
Graphics2D g2d = (Graphics2D) g;
// 设置画笔粗细
g2d.setStroke(new BasicStroke(5.0f));
// 设置画笔颜色
g2d.setColor(Color.GRAY);
// 设置画笔字体
g2d.setFont(new Font("宋体", Font.BOLD, 14));
}
评论(0)