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

前端 未结 2 1410
抹茶落季
抹茶落季 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();
    
    0 讨论(0)
  • 2021-01-05 19:41

    A JTable is notoriously difficult to get rendered correctly for images (or I guess, printing). See this thread on which some of the gurus weigh in with tips.

    Looking closely at the screenshots of that thread suggests that the default Metal table has no border on the far left.

    The table in Nimbus PLAF does, though.

    0 讨论(0)
提交回复
热议问题