Hello all,

I've been using the iText classes (v0.96) with the JDK1.4 for a week and I 
think they're great.  I have a question about the cell horizontal alignment 
using the above method.  I've searched the archives for 
the .setDefaultHorizontalAlignment() method but didn't find my answer.

I've written a servlet to stream the results of a query using RtfWriter and 
com.lowagie.text.table to the user as an rtf document.  The problem I'm having 
is the cell alignment of 1 column in the table does not change when I use 
setDefaultHorizontalAlignment().  I saw a similar example of this in 
Chap0510.java where it changes the cell alignment 
using .setDefaultHorizontalAlignment(), but using the code below the cell 
alignment for "db_grade" does not become centered, it stays left justified.  In 
the commented out code section below I found a way to make the cell centered, 
but I'm wondering why setDefaultHorizontalAlignment() doesn't work.

             Document document = new Document(PageSize.A4.rotate()); 

             try
             {
                response.setContentType("application/rtf");  
                response.setHeader("Content-
Disposition","attachment;filename=\""+filename+"\"");
                RtfWriter.getInstance(document, response.getOutputStream());

                  //Find the JDBC driver
                Class.forName(sqlDriver);         //establish the connection
                conn = java.sql.DriverManager.getConnection(sqlURL);
                stmt = conn.createStatement();

                document.open();

                if (reportType.equals("Parent"))
                {
                   String db_student_name = "";
                   int db_stud_id = 0;
                   String db_grade = "";
                   String db_parent = "";
                   String db_telephone = "";
                   String db_address = "";
                   String db_email = "";
                   String db_relation = "";                    
                    
                   HeaderFooter header = new HeaderFooter(new Phrase
(DateFormat.getDateInstance(FULL).format(today)), false);
                   header.setBorder(Rectangle.NO_BORDER);
                   document.setHeader(header);
                   
                   document.add(new Paragraph(""));
                   document.add(new Paragraph("Teacher: "+teacherName, new Font
(Font.TIMES_NEW_ROMAN, 12,Font.BOLD)));
                   document.add(new Paragraph(courseName+", 
Period "+periodName, new Font(Font.TIMES_NEW_ROMAN, 12,Font.BOLD)));

                   rs  = stmt.executeQuery("SELECT DISTINCT stud_id, count
(stud_id) as count, ASTU_GRADE, ASTU_FIRSTNAME, ASTU_MIDDLENAME, ASTU_LASTNAME, 
APRN_FIRSTNAME, APRN_LASTNAME, APRN_MIDDLENAME, STR_APRN_TELEPHONE, 
aprn_address, aprn_city, aprn_zipcode, aprn_state, APRN_EMAILADDR, 
APRN_RELATION FROM "+libname+".student_lookup WHERE stud_id IN (select distinct 
stud_id FROM "+libname+".progfilters_full "+_where1+
                                           ") group by stud_id having 
aprn_sequence=min(aprn_sequence) order by ASTU_LASTNAME;");
                   
                   Table datatable = new Table(6);

                   datatable.setBorderWidth(1);
                   datatable.setPadding(4);
                   datatable.setSpacing(0);
                   int headerwidths[] = {15, 5, 20, 10, 30, 20};
                   datatable.setWidths(headerwidths);
                   datatable.setWidth(100);
                   datatable.setDefaultCellBackgroundColor(new Color
(255,153,51));

                   Cell cell = new Cell(new Phrase("Student Name", 
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));

                   cell.setHeader(true);
                   datatable.addCell(cell);
                   datatable.addCell(new Phrase("Grade",  FontFactory.getFont
(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));
                   datatable.addCell(new Phrase("Parent/Guardian Name",  
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));
                   datatable.addCell(new Phrase("Telephone",  
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));
                   datatable.addCell(new Phrase("Address",  FontFactory.getFont
(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));
                   datatable.addCell(new Phrase("Email",  FontFactory.getFont
(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0,0,255))));
                   datatable.setDefaultCellBackgroundColor(null);
            
                   datatable.endHeaders();
                   datatable.setDefaultCellBorderWidth(1);
                   datatable.setDefaultRowspan(1);

                  while (rs.next())
                   {
                      db_student_name = rs.getString("ASTU_LASTNAME").trim()
+", "+rs.getString("ASTU_FIRSTNAME").trim();
                      db_stud_id      = rs.getInt("stud_id");
                      db_grade        = rs.getString("astu_grade");
                      db_parent       = rs.getString("APRN_FIRSTNAME").trim()
+" "+rs.getString("APRN_MIDDLENAME").trim()+" "+rs.getString
("APRN_LASTNAME").trim();
                      db_telephone    = rs.getString("STR_APRN_TELEPHONE");
                      db_address      = rs.getString("aprn_address").trim()
+" "+rs.getString("aprn_city").trim()+", "+rs.getString("aprn_state").trim()
+" "+rs.getString("aprn_zipcode").trim();
                      db_email        = rs.getString("APRN_EMAILADDR");
                      db_relation     = rs.getString("APRN_RELATION");
                      
                      datatable.setDefaultHorizontalAlignment
(Element.ALIGN_LEFT);                      
                      datatable.setDefaultCellBackgroundColor(new Color
(255,255,200));
                      datatable.addCell(db_student_name);
                      datatable.setDefaultCellBackgroundColor(null);
                      datatable.setDefaultHorizontalAlignment
(Element.ALIGN_CENTER);

//                      Cell cell1 = new Cell(db_grade);
//                      cell1.setHorizontalAlignment(Cell.ALIGN_CENTER);
//                      table.addCell(cell1);
                      datatable.addCell(db_grade);
                      datatable.setDefaultHorizontalAlignment
(Element.ALIGN_LEFT);
                      datatable.addCell(db_parent);
                      datatable.addCell(db_telephone);
                      datatable.addCell(db_address);
                      datatable.addCell(db_email);
                   }

                   document.add(datatable);
                }
             }






---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/




-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to