dimanche 9 août 2020

if statement in new Cell statement

I use iText to create a table that will be put in an PDF-file. While creating a table using a for-loop, I want to implement an if-statement that checks the for-loop counter. If the counter equals... than the table cell will get a specific format. I can't figure out where to put in the for-loop. This is my code so far:

    for (int counter = 0; counter < 8; counter++) {
        table.addCell(new Cell()
                            .setBorder(Border.NO_BORDER)
                            .setPadding(1)
                            if (counter == 6) {
                                .setFont(f);
                            });
        table.addCell(new Cell()
                            .setTextAlignment(TextAlignment.LEFT)
                            .setBorder(Border.NO_BORDER)
                            .add(new Paragraph(order.getReceiver().getAllReceiverDetails().get(counter)))
                            .setPadding(1));
        table.addCell(new Cell()
                            .setTextAlignment(TextAlignment.LEFT)
                            .setBorder(Border.NO_BORDER)
                            .add(new Paragraph(order.getSender().getAllSenderDetails().get(counter)))
                            .setPadding(1));
    }

Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire