JAVA 如何给组件绘制边框

Python014

JAVA 如何给组件绘制边框,第1张

调用组件

setBorder(new LineBorder(Color color))

可以绘制组件的边框,边框为像素为1,颜色为color的直线

具体可以参考组件setBorder()方法和LineBorder边框类的API

还有其他的边框类

你可以参考下这个代码:

Workbook workbook=new HSSFWorkbook() // 定义一个新的工作簿

Sheet sheet=workbook.createSheet("第一个Sheet页")  // 创建第一个Sheet页

Row row=sheet.createRow(1) // 创建一个行

Cell cell=row.createCell(1) // 创建一个单元格

cell.setCellValue(4)

// 设置单元格边框

CellStyle cellStyle=workbook.createCellStyle() 

cellStyle.setBorderBottom(CellStyle.BORDER_THIN) // 底部边框

cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()) // 底部边框颜色

cellStyle.setBorderLeft(CellStyle.BORDER_THIN)  // 左边边框

cellStyle.setLeftBorderColor(IndexedColors.GREEN.getIndex()) // 左边边框颜色

cellStyle.setBorderRight(CellStyle.BORDER_THIN) // 右边边框

cellStyle.setRightBorderColor(IndexedColors.BLUE.getIndex())  // 右边边框颜色

cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED) // 上边边框

cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex())  // 上边边框颜色