optimus
optimus

Reputation: 47

iText, insert new blank line inside PdfPTable column

How do I insert a new blank line inside a PdfPTable column. \n and n number of spaces has not done the trick for me. This is the java code I am working with.

chtbc_report1_table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
    {"H.B.G", "Some Value", "lbs/kg", "Adult M : 120lbs \n Adult F : 90lbs"},
    .....
    .....
    //Other rows
    },
new String [] {
    "Investigation", "Result", "Unit", "Weight"
}
));

I want to put a new line between "Adult M : 120lbs **\n** Adult F : 90lbs"

UPDATE

This is the code I have used for creating a PdfPTable

document.open();

    PdfPTable pdfTable = new PdfPTable(chtbc_report1_table.getColumnCount());    
    for (int rows = 0; rows < chtbc_report1_table.getRowCount(); rows++) {
        for (int cols = 0; cols < chtbc_report1_table.getColumnCount(); cols++) {
            pdfTable.addCell(chtbc_report1_table.getModel().getValueAt(rows, cols).toString());

        }
    }
    float[] columnWidths_pdfTable = new float[]{30f, 25f, 40f, 50f};
    pdfTable.setWidths(columnWidths_pdfTable);
    document.add(pdfTable);

document.close()

Any suggestions would help.

Upvotes: 1

Views: 1878

Answers (1)

mustangDC
mustangDC

Reputation: 967

Oh, that is quite simple indeed. Try the following as the same works for me :-

Table Contents

jTable1.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {"Lorem Ipsum", "Next Line here \n, Another new line\n, Two new lines\n\nI will end here"},
            {"Lorem Ipsum", "Another cell to demonstrate \n\n\n\n4 New lines above and two below \n\n"}
        },
        new String [] {
            "Text", "Long Text"
        }
    ));

Let me know, if that worked. And the PdfPtable should be the same.

Upvotes: 2

Related Questions