Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is iText's PdfWriter printing JTextFields black when exported as a runnable jar?
    text
    copied!<p>I hava got a strange conundrum. I am currently trying to make a Runnable Jar of an Eclipse project I'm working on that has a number of JTextField's and JFormattedTextField's all nicely arranged in JPanel's. I am then taking these JPanel's and printing them out use iText's nice PdfWriter.</p> <p>The issue is this: In Eclipse, this prints out just fine. When I export my project into a runnable jar, I get the following:</p> <p><img src="https://i.stack.imgur.com/pAkqu.jpg" alt="My problem"></p> <p>All of those black rectangles are where my JTextField's and JFormattedTextField's are located.</p> <p>Does anyone have any idea what may be causing this? This is how I am printing things out, and remember, it is working in Eclipse but not when exported as runnable jar:</p> <pre><code>private void print() throws DocumentException, IOException { Document document = new Document(PageSize.LETTER, 0, 0, 0, 0); File file = new File(System.getProperty("user.home") + File.separator + "Desktop" + File.separator + "temp.pdf"); if (!file.exists()) { file.createNewFile(); } PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); PdfContentByte contentByte = writer.getDirectContent(); int x = (int) document.getPageSize().getWidth() / 2 - 250; int y = (int) document.getPageSize().getHeight() - 375; for (int i = 0; i &lt; jobs.size(); i++) { jobs.get(i).setFocusable(false); contentByte.moveTo(0, y + 235); contentByte.lineTo(document.getPageSize().getWidth(), y + 235); contentByte.closePathStroke(); y += 5; PdfTemplate template = contentByte.createTemplate(600, 250); @SuppressWarnings("deprecation") Graphics2D g2 = template.createGraphics(600, 250); jobs.get(i).print(g2); g2.dispose(); contentByte.addTemplate(template, x, y); y -= 105; jobs.get(i).setFocusable(true); } contentByte.moveTo(0, y + 235); contentByte.lineTo(document.getPageSize().getWidth(), y + 235); contentByte.closePathStroke(); y = 25; PdfTemplate template = contentByte.createTemplate(600, 25); @SuppressWarnings("deprecation") Graphics2D g2 = template.createGraphics(600, 25); total.setFocusable(false); totalPanel.setOpaque(false); totalPanel.print(g2); g2.dispose(); contentByte.addTemplate(template, x - 65, y); total.setFocusable(true); totalPanel.setOpaque(true); document.close(); } </code></pre> <p>Thanks for all of your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload