Cell Horizontal Alignment

View: New views
2 Messages — Rating Filter:   Alert me  

Cell Horizontal Alignment

by Kharas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I'm trying to change the horizontal alignment of a table cell containing just an Image, but the call to Cell.setHorizontalAlignment(int) has no effect. It works fine when I add some text to the cell thought.

Here is the code:

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.RtfWriter2;

public class RtfTable {

    public static void main(String[] args) {

        Document document = new Document(PageSize.A4);

        try {
            RtfWriter2 rtf = RtfWriter2.getInstance(document, new FileOutputStream("Table.rtf"));
               
            Table table = new Table(2);
           
            table.addCell("Cell 1\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

            Image image = Image.getInstance("9016.png");
           
            Cell cell2 = new Cell();
           
            cell2.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell2.setVerticalAlignment(Cell.ALIGN_MIDDLE);            
            cell2.add(image);
             
            table.addCell(cell2);

            document.open();
           
            document.add(table);
           
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    }
}


I would really appreciatte it if you could tell me what am I doing wrong.

Thanks.

Re: Cell Horizontal Alignment

by Kharas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Solved, Thanks.

Kharas wrote:
Hi

I'm trying to change the horizontal alignment of a table cell containing just an Image, but the call to Cell.setHorizontalAlignment(int) has no effect. It works fine when I add some text to the cell thought.

Here is the code:

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.RtfWriter2;

public class RtfTable {

    public static void main(String[] args) {

        Document document = new Document(PageSize.A4);

        try {
            RtfWriter2 rtf = RtfWriter2.getInstance(document, new FileOutputStream("Table.rtf"));
               
            Table table = new Table(2);
           
            table.addCell("Cell 1\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

            Image image = Image.getInstance("9016.png");
           
            Cell cell2 = new Cell();
           
            cell2.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell2.setVerticalAlignment(Cell.ALIGN_MIDDLE);            
            cell2.add(image);
             
            table.addCell(cell2);

            document.open();
           
            document.add(table);
           
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    }
}


I would really appreciatte it if you could tell me what am I doing wrong.

Thanks.