How to export a complete JTable component in pdf at a specific coordinate

前端 未结 2 1485
抹茶落季
抹茶落季 2021-01-05 18:39

In my project I have to print JTable components in a pdf with all the customizations(like borders,colors etc). For this requirement I searched a little bit and found one cod

2条回答
  •  死守一世寂寞
    2021-01-05 19:32

    Hi I resolved the code by adding like below:-

    cb.saveState();
    
    PdfTemplate pdfTemplate = cb.createTemplate(table.getWidth(), table.getHeight());
    Graphics2D g2 = pdfTemplate.createGraphics(table.getWidth(), table.getHeight());
    /*g2.setColor(Color.BLACK);
    g2.drawRect(x-2, y-2, table.getWidth()+2, table.getHeight()+2);*/
    table.print(g2);
    System.out.println("x="+x + "," + "y=" + y);
    cb.addTemplate(pdfTemplate, x, y);
    g2.dispose();
    cb.restoreState();
    

提交回复
热议问题