将JTable转变为image

    技术2022-05-11  21

    调试了半天,老是出不来表头,只有数据.郁闷..后面试了下tableHeader,成功了 BufferedImage image=new BufferedImage(table.getWidth(),table.getHeight(),BufferedImage.TYPE_INT_RGB);         Graphics2D    g3=image.createGraphics();         table.paint(g3);         table.getTableHeader().paint(g3);         try{             ImageIO.write(image, "png", new File("D://test.png"));         }catch(Exception e){             e.printStackTrace();         } 注意1个地方: table.paint(g3)一定需要. 否则就只有表头,表格内部内容就是黑的

    最新回复(0)