Image in header of print (JTable)

Hello,
I have a question about printing a JTable. I use the following code which works well but I want to extend my print with a image (a logo) in the header of every page. What is the best way to achieve this?
My second question is how I can change the font size of the header?
Thanks for your reply.
Regards Stefan.
MessageFormat header = new MessageFormat("Test");
MessageFormat footer = new MessageFormat("Page - {0}");
try {
    if (!myTable.print(JTable.PrintMode.FIT_WIDTH
, header, footer, true, null, true)) {
        System.err.println("User cancelled printing");
} catch (java.awt.print.PrinterException e) {
    System.err.format("Cannot print %s%n", e.getMessage());
}     

The API provided by the JTable class is described as simple, and indeed it is. To obtain more complex printing, you need to use the JTable.getPrintable method and do some extra work to get the results desired.
There are also several third party codes you can try. Do a search on google to search what you find
ICE

Similar Messages

  • How to print (on paper) expected header and footer while printing Jtable

    Hello,
    I am printing jtable on paper using dot mtix printer.In header i want to print some name date and number like below
    Sun
    Date:12/8/20010 No.12334
    | col1 | col2 |
    | col1 | col2 |
    footer
    When i am trying to print header its Font size is very big and its in one line.How i can use expected font and expected text here.
    i am using jtable print method(which contin header and footer printing facility)
    Edited by: Ashtekar on Aug 12, 2010 5:18 AM

    I also once hoped for an easy way to modify a table's header and footer, but found no way.
    Yet it is possible.

  • Print Jtable with multiline header?

    i want to print jtable with multi-lines header and footer
    using the print function that takes MessageFormat as header and footer
    i used MessageFormat header = new MessageFormat("hello\r\nworld");and i used '\n' only
    but it was printed all in the same line
    thnx in advance

    You can try something on the below lines. Set your custom renderer for the tableheader.
    public class MultiLineHeaderRenderer extends DefaultTableCellRenderer{
            public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected, boolean hasFocus, int row, int column) {
                         JLabel label = (JLabel) super.getTableCellRendererComponent( table,  value,
                              isSelected,  hasFocus,  row,  column);
                        label.setText("<html>a<br>b</html>");
                        return label;
        }Not the best way to do it. And might need to some modifications too to set the font position etc.

  • Print JTable with column heading

    Hi,
    I'm very new to this JTable. I'm try to print a Jtable using the print() function (from JDK 1.5)
    JTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat(
    _tabledata.getTitle() ),
    new MessageFormat("Page {0,number}"));
    The problem I have is that some time it print and other time it doens't print. Also, if it doesn't print, then the program become very slow or not respond. Is that the probelm with the new JDK or am I doing something wrong?
    Thanks for you help.

    Don't rely on JTable.print() methods too much.
    Sadly Sun didn't think anyone would need to print anything from java so support was added late and half heartedly (programmers hate printing stuff)
    If you are new to java you need to focus on something simpler than printing documents; unfortunatly printing is a tedious burdonsome task for experreineced developers
    for example: learn how to output your data from a table into an HTML formate/file; you can build beautiful reports/printouts easily and view them in java components easily but you will probably want to print them from a browser.
    Even if you find a class or two to help with your printing efforts on the net you will find you need to know many other generic complicated aspects of java to continue
    Sean

  • Print - JTable with a TITLE on each page

    Hi! someone know haw can I print a MY TITLE on each page that I print ?
    ----->MY TITLE<----
    | co1 | col2 | col3 | col4 |
    |dtxxz|dtxyz|dtxyz|dtxyz|
    |dtxxz|dtxyz|dtxyz|dtxyz|
    |dtxxz|dtxyz|dtxyz|dtxyz|
    PAGE 1
    I try that :
    g.drawString("MY TITLE", 100,50);
    but the table header hide (writing over) my title
    Here is my call :
    public int print(Graphics g, PageFormat pageFormat, int pageIndex)
    throws PrinterException {
         Graphics2D g2 = (Graphics2D) g;
         g2.setColor(Color.black);
         int fontHeight = g2.getFontMetrics().getHeight();
         int fontDesent = g2.getFontMetrics().getDescent();
         pageFormat.setOrientation(pageFormat.LANDSCAPE);
         //leave room for page number
         double pageHeight = pageFormat.getImageableHeight() - fontHeight;
         double pageWidth = pageFormat.getImageableWidth();
         double tableWidth =
              (double) getCurrentTable().getColumnModel().getTotalColumnWidth();
         double scale = 1;
         if (tableWidth >= pageWidth) {
              scale = pageWidth / tableWidth;
         double headerHeightOnPage =
              getCurrentTable().getTableHeader().getHeight() * scale ;
         double tableWidthOnPage = tableWidth * scale;
         double oneRowHeight =
              (getCurrentTable().getRowHeight() + getCurrentTable().getRowMargin()) * scale;
         int numRowsOnAPage = (int) ((pageHeight - headerHeightOnPage) / oneRowHeight);
         double pageHeightForTable = oneRowHeight * numRowsOnAPage;
         int totalNumPages =
              (int) Math.ceil(((double) getCurrentTable().getRowCount()) / numRowsOnAPage);
         if (pageIndex >= totalNumPages) {
              return NO_SUCH_PAGE;
         g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
         g2.drawString(
              "Page: " + (pageIndex + 1),
              (int) pageWidth / 2 - 35,
              (int) (pageHeight + fontHeight - fontDesent));
         //bottom center
         g2.translate(0f, headerHeightOnPage);
         g2.translate(0f, -pageIndex * pageHeightForTable);
         //TODO this next line treats the last page as a full page
         g2.setClip(
              0,
              (int) (pageHeightForTable * pageIndex),
              (int) Math.ceil(tableWidthOnPage),
              (int) Math.ceil(pageHeightForTable));
         g2.scale(scale, scale);
         getCurrentTable().paint(g2);
         g2.scale(1 / scale, 1 / scale);
         g2.translate(0f, pageIndex * pageHeightForTable);
         g2.translate(0f, -headerHeightOnPage);
         g2.setClip(
              0,
              0,
              (int) Math.ceil(tableWidthOnPage),
              (int) Math.ceil(headerHeightOnPage));
         g2.scale(scale, scale);
         getCurrentTable().getTableHeader().paint(g2); //paint header at top
         return Printable.PAGE_EXISTS;
    Thanks

    //Solution-------------------------------------------------------------------------------------------------------
    // PRINT : CENTER HEADER TITLE ON EACH PAGE
    : PAGE NUMBER ON EACH PAGE
    : USE A PREVIEW WINDOW
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.awt.*;
    import java.awt.event.*;
    * File: PrintTable.java
    * (C) Copyright Corp. 2001 - All Rights Reserved.
    * Print a JTable data
    public class PrintTable implements Printable {
    * Insert the method's description here.
    * Creation date: (03-13-2002 13:50:41)
    * @param g java.awt.Graphics
    * @param pg java.awt.print.PageFormat
    * @param i int
    public int print(Graphics g, PageFormat pageFormat,
         int pageIndex) throws PrinterException {
         try{
              Graphics2D g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              int fontHeight = g2.getFontMetrics().getHeight();
              int fontDesent = g2.getFontMetrics().getDescent();
              // Normalize the header color
              // he title of the report is not printed if the color of the header is different of these colors
              m_table.getTableHeader().setBackground(new java.awt.Color(204,204,204));
              m_table.getTableHeader().setForeground(new java.awt.Color(0,0,0));
              //leave room for page number
              double pageHeight = pageFormat.getImageableHeight() - fontHeight;
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) m_table.getColumnModel().getTotalColumnWidth();
              double scale = 1;
              if (tableWidth >= pageWidth) {
                   scale = pageWidth / tableWidth;
              // Get the size of the table header
              double headerHeightOnPage = m_table.getTableHeader().getHeight() * scale;
              // Get the table size on a page
              double tableWidthOnPage = tableWidth * scale;
              // Title Height
              double titleHeightOnPage = 0;
              if( m_title != null ){
                   titleHeightOnPage = ((double)m_title.getFontMetrics(m_title.getFont()).getHeight() + 40) * scale;
              // Get size of a row
              double oneRowHeight =
                   (m_table.getRowHeight() + m_table.getRowMargin()) * scale;
              int numRowsOnAPage = (int) ((pageHeight - headerHeightOnPage - titleHeightOnPage) / oneRowHeight);
              // Get number of row in a page
              double pageHeightForTable = oneRowHeight * numRowsOnAPage;
              // Get the number of page to print
              int totalNumPages =
                   (int) Math.ceil(((double) m_table.getRowCount()) / numRowsOnAPage);
              if (pageIndex >= totalNumPages) {
                   return NO_SUCH_PAGE;
              // Print the page label at bottom center
              g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
              g2.drawString(
                   "Page: " + (pageIndex + 1),
                   (int) pageWidth / 2 - 35,
                   (int) (pageHeight + fontHeight - fontDesent));
              g2.translate(0f, headerHeightOnPage + titleHeightOnPage);
              g2.translate(0f, -pageIndex * pageHeightForTable);
              //If this piece of the table is smaller than the size available,
              //clip to the appropriate bounds.
              if (pageIndex + 1 == totalNumPages) {
                   int lastRowPrinted = numRowsOnAPage * pageIndex;
                   int numRowsLeft = m_table.getRowCount() - lastRowPrinted;
                   g2.setClip(
                        0,
                        (int) (pageHeightForTable * pageIndex),
                        (int) Math.ceil(tableWidthOnPage),
                        (int) Math.ceil(oneRowHeight * numRowsLeft));
              //else clip to the entire area available.
              else {
                   g2.setClip(
                        0,
                        (int) (pageHeightForTable * pageIndex),
                        (int) Math.ceil(tableWidthOnPage),
                        (int) Math.ceil(pageHeightForTable));
              g2.scale(scale, scale);
              m_table.paint(g2);
              g2.scale(1 / scale, 1 / scale);
              g2.translate(0f, pageIndex * pageHeightForTable);
              g2.translate(0f, -headerHeightOnPage );
              g2.setClip(
                   0,
                   0,
                   (int) Math.ceil(tableWidthOnPage),
                   (int) Math.ceil(headerHeightOnPage));
              g2.scale(scale, scale);
              // Paint header at the top of the page
              m_table.getTableHeader().paint(g2);
              g2.scale(1 / scale, 1/ scale);
              g2.translate(0f, -titleHeightOnPage);
              g2.setClip(
                   0,
                   0,
                   (int) Math.ceil(tableWidthOnPage),
                   (int) Math.ceil(titleHeightOnPage));
              // Paint title
              if( m_strTitle != null ){
                   //Center
                   g2.translate((pageFormat.getImageableWidth() / 2) -
                                  (m_title.getFontMetrics(m_title.getFont()).stringWidth(m_title.getText()) / 2 ),
                                  0f );
                   g2.drawString(m_title.getText(), 0, 10);
              }else if ( m_title != null ){
                   //Center
                   g2.translate((pageFormat.getImageableWidth() / 2) -
                                  (m_title.getFontMetrics(m_title.getFont()).stringWidth(m_title.getText()) / 2 ),
                                  0f );
                   m_title.paint(g2);     
         }catch (Exception e){
              e.printStackTrace();
              return Printable.PAGE_EXISTS;
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, String title) {
         try {
              m_table = table;
              m_strTitle = title;
              m_data     = m_table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, prnJob.defaultPage());
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
         protected static PrintTable instance     = new PrintTable();
         public static int LANDSCAPE = PageFormat.LANDSCAPE;
         protected static TableModel m_data;
         protected static int m_maxNumPage           = 1;
         protected static String          m_strTitle = null;
         protected static JTable      m_table;
         protected static JLabel      m_title          = null;
         // Paper orientation
         public static int PORTRAIT = PageFormat.PORTRAIT;
         private final static String PREVIEW_LBL = "Aper�u avant impression...";
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table) {
         m_table = table;
         m_data      = table.getModel();
         PrinterJob prnJob = PrinterJob.getPrinterJob();
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             prnJob.defaultPage());
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table, PageFormat pf) {
         m_table = table;
         m_data      = table.getModel();
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             pf);
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table, String title) {
         m_table = table;
         m_data      = table.getModel();
         m_strTitle = title;
         m_title = new JLabel(title);
         PrinterJob prnJob = PrinterJob.getPrinterJob();
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             prnJob.defaultPage());
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table, String title, PageFormat pf) {
         m_table = table;
         m_data      = table.getModel();
         m_strTitle = title;
         m_title = new JLabel(title);
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             pf);
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table, JLabel title) {
         m_table = table;
         m_data      = table.getModel();
         m_title = title;
         PrinterJob prnJob = PrinterJob.getPrinterJob();
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             prnJob.defaultPage());
    * Insert the method's description here.
    * Creation date: (03-13-2002 10:12:41)
    public static void preview(JTable table, JLabel title, PageFormat pf) {
         m_table = table;
         m_data      = table.getModel();
         m_title = title;
         new PrintPreview(PrintTable.instance,
                             PREVIEW_LBL,
                             pf);
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, String title, PageFormat pf) {
         try {
              m_table = table;
              m_strTitle = title;
              m_data     = m_table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, pf);
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, String title, PageFormat pf, int orientation) {
         try {
              m_table = table;
              m_strTitle = title;
              m_data     = m_table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, prnJob.defaultPage());
              pf.setOrientation(orientation);
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, JLabel title) {
         try {
              m_table = table;
              m_title = title;
              m_data = table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, prnJob.defaultPage());
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, JLabel title, PageFormat pf) {
         try {
              m_table = table;
              m_title = title;
              m_data      = table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, pf);
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
    * Show a print dialog box
    * Call the method to print
    * @param JTable table : table to print
    * @param String title : title of the table
    public static void print(JTable table, JLabel title, PageFormat pf, int orientation) {
         try {
              m_table = table;
              m_title = title;
              m_data      = table.getModel();
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(PrintTable.instance, pf);
              // if the print job is cancelled
              if (!prnJob.printDialog())
                   return;
              pf.setOrientation(orientation);
              // print the table
              prnJob.print();
         } catch (PrinterException pe) {
              pe.printStackTrace();
              System.err.println("Printing error: " + pe.toString());
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.util.*;
    import java.awt.print.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    public class PrintPreview extends JFrame
    protected int m_wPage;
    protected int m_hPage;
    protected Printable m_target;
    protected JComboBox m_cbScale;
    protected PreviewContainer m_preview;
    private String lblBtnClose           = "Fermer";
    private String lblBtnPrint           = "Imprimer...";
    protected PageFormat m_pf;
    private String[] scales                = { "10 %", "25 %", "50 %", "100 %" };
    public PrintPreview(Printable target, String title, PageFormat pf) {
         super(title);
         setSize(600, 400);
         m_target = target;
         m_pf = pf;
         JToolBar tb = new JToolBar();
         JButton bt = new JButton(this.lblBtnPrint);
         ActionListener lst = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              try {
              // Use default printer, no dialog
              PrinterJob prnJob = PrinterJob.getPrinterJob();
              prnJob.setPrintable(m_target, m_pf);
              setCursor( Cursor.getPredefinedCursor(
                   Cursor.WAIT_CURSOR));
              prnJob.print();
              setCursor( Cursor.getPredefinedCursor(
                   Cursor.DEFAULT_CURSOR));
              dispose();
              catch (PrinterException ex) {
              ex.printStackTrace();
              System.err.println("Printing error: "+ex.toString());
         bt.addActionListener(lst);
         bt.setAlignmentY(0.5f);
         bt.setMargin(new Insets(4,6,4,6));
         tb.add(bt);
         bt = new JButton(this.lblBtnClose);
         lst = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              dispose();
         bt.addActionListener(lst);
         bt.setAlignmentY(0.5f);
         bt.setMargin(new Insets(2,6,2,6));
         tb.add(bt);
         m_cbScale = new JComboBox(scales);
         lst = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              Thread runner = new Thread() {
              public void run() {
                   String str = m_cbScale.getSelectedItem().
                   toString();
                   if (str.endsWith("%"))
                   str = str.substring(0, str.length()-1);
                   str = str.trim();
                   int scale = 0;
                   try { scale = Integer.parseInt(str); }
                   catch (NumberFormatException ex) { return; }
                   int w = (int)(m_wPage*scale/100);
                   int h = (int)(m_hPage*scale/100);
                   Component[] comps = m_preview.getComponents();
                   for (int k=0; k<comps.length; k++) {
                   if (!(comps[k] instanceof PagePreview))
                        continue;
                   PagePreview pp = (PagePreview)comps[k];
                        pp.setScaledSize(w, h);
                   m_preview.doLayout();
                   m_preview.getParent().getParent().validate();
              runner.start();
         m_cbScale.addActionListener(lst);
         m_cbScale.setMaximumSize(m_cbScale.getPreferredSize());
         m_cbScale.setEditable(true);
         tb.addSeparator();
         tb.add(m_cbScale);
         getContentPane().add(tb, BorderLayout.NORTH);
         m_preview = new PreviewContainer();
         PrinterJob prnJob = PrinterJob.getPrinterJob();
         PageFormat pageFormat = pf;
         if (pageFormat.getHeight()==0 || pageFormat.getWidth()==0) {
         System.err.println("Unable to determine default page size");
              return;
         m_wPage = (int)(pageFormat.getWidth());
         m_hPage = (int)(pageFormat.getHeight());
         int scale = 10;
         int w = (int)(m_wPage*scale/100);
         int h = (int)(m_hPage*scale/100);
         int pageIndex = 0;
         try {
         while (true) {
              BufferedImage img = new BufferedImage(m_wPage,
              m_hPage, BufferedImage.TYPE_INT_RGB);
              Graphics g = img.getGraphics();
              g.setColor(Color.white);
              g.fillRect(0, 0, m_wPage, m_hPage);
              if (target.print(g, pageFormat, pageIndex) !=
              Printable.PAGE_EXISTS)
              break;
              PagePreview pp = new PagePreview(w, h, img);
              m_preview.add(pp);
              pageIndex++;
         catch (PrinterException e) {
         e.printStackTrace();
         System.err.println("Printing error: "+e.toString());
         JScrollPane ps = new JScrollPane(m_preview);
         getContentPane().add(ps, BorderLayout.CENTER);
         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
         setVisible(true);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    * Insert the type's description here.
    * Creation date: (03-12-2002 14:17:45)
    * @author: Alexandre Spain
    public class PreviewContainer extends JPanel {
         protected int H_GAP = 16;
         protected int V_GAP = 10;
    * PreviewContainer constructor comment.
    public PreviewContainer() {
         super();
    public void doLayout() {
         Insets ins = getInsets();
         int x = ins.left + H_GAP;
         int y = ins.top + V_GAP;
         int n = getComponentCount();
         if (n == 0)
              return;
         Component comp = getComponent(0);
         Dimension dc = comp.getPreferredSize();
         int w = dc.width;
         int h = dc.height;
         Dimension dp = getParent().getSize();
         int nCol = Math.max((dp.width-H_GAP)/(w+H_GAP), 1);
         int nRow = n/nCol;
         if (nRow*nCol < n)
              nRow++;
         int index = 0;
         for (int k = 0; k<nRow; k++) {
              for (int m = 0; m<nCol; m++) {
                   if (index >= n)
                        return;
                   comp = getComponent(index++);
                   comp.setBounds(x, y, w, h);
                   x += w+H_GAP;
              y += h+V_GAP;
              x = ins.left + H_GAP;
    public Dimension getMaximumSize() {
         return getPreferredSize();
    public Dimension getMinimumSize() {
         return getPreferredSize();
    public Dimension getPreferredSize() {
         int n = getComponentCount();
         if (n == 0)
              return new Dimension(H_GAP, V_GAP);
         Component comp = getComponent(0);
         Dimension dc = comp.getPreferredSize();
         int w = dc.width;
         int h = dc.height;
         Dimension dp = getParent().getSize();
         int nCol = Math.max((dp.width-H_GAP)/(w+H_GAP), 1);
         int nRow = n/nCol;
         if (nRow*nCol < n)
              nRow++;
         int ww = nCol*(w+H_GAP) + H_GAP;
         int hh = nRow*(h+V_GAP) + V_GAP;
         Insets ins = getInsets();
         return new Dimension(ww+ins.left+ins.right,
                                  hh+ins.top+ins.bottom);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    * Insert the type's description here.
    * Creation date: (03-12-2002 14:17:06)
    * @author: Alexandre Spain
    public class PagePreview extends JPanel {
         protected int m_w;
         protected int m_h;
         protected Image m_source;
         protected Image m_img;
    * PagePreview constructor comment.
    * @param target java.awt.print.Printable
    public PagePreview(int w, int h, Image source) {
         m_w = w;
         m_h = h;
         m_source= source;
         m_img = m_source.getScaledInstance(m_w, m_h,
              Image.SCALE_SMOOTH);
         m_img.flush();
         setBackground(Color.white);
         setBorder(new MatteBorder(1, 1, 2, 2, Color.black));
    public Dimension getMaximumSize() {
         return getPreferredSize();
    public Dimension getMinimumSize() {
         return getPreferredSize();
    public Dimension getPreferredSize() {
         Insets ins = getInsets();
         return new Dimension(m_w+ins.left+ins.right,
                                  m_h+ins.top+ins.bottom);
    public void paint(Graphics g) {
         g.setColor(getBackground());
         g.fillRect(0, 0, getWidth(), getHeight());
         g.drawImage(m_img, 0, 0, this);
         paintBorder(g);
    public void setScaledSize(int w, int h) {
         m_w = w;
         m_h = h;
         m_img = m_source.getScaledInstance(m_w, m_h,
         Image.SCALE_SMOOTH);
         repaint();

  • Image in Word doc prints Jaggy

    I've inserted my company's logo into a Word document for the header, but every time I print it, it to a PDF, it looks very jaggy.
    I have a sample of the logo in various forms: http://img18.imageshack.us/img18/483/jaggy.png
    1. This is how it looks in the word document.
    2. This is how it looks when I print it as a PDF-  I set the PDF printer to Hi Quality and it actually makes the font on the right look better, but the logo (PNG) on the left looks very bad.  The text at the bottom is almost illegible in the PDF.
    3. This is the logo alone printed as a PDF through GIMP.
    4. This is the logo printed on a gradient background through GIMP.
    When printing the image to an actual printer, it looks exactly like it does in Word.

    png is really not appropriate for a logo, it should be created as a vector graphic so that it will display well no matter what reasonable resolution is chosen. Is the logo available in a better format?

  • Print JTable with row headers

    I am using the fancy new printing capablities in java 1.5 to print my JTable and wow is it ever slick!
    PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
    set.add(OrientationRequested.LANDSCAPE);
    this.matrixJTable.print(JTable.PrintMode.NORMAL, null, null, true, set, false);Its just that easy. Way to go sun!
    The one problem that I am encountering is that my row headers don't print. The problem is that JTables don't support row headers, you have to use a JScrollPane for that.
    I need a way to print my JTable so that the row headers show up in the printout... and hopefully still use the warm and fuzzy new printing capabilities of JTable printing in java 1.5.
    (ps/ Isn't it time to add row header support to JTables?)

    The problem is that JTables don't support row headers, you have to use a JScrollPane for that.Well technically JTable's don't really support column headers either. It is a seperate component (JTableHeader). A JTable will automatically add its table header to the table header area of a JScrollPane. (but you don't have to use a jscrollpane to see the column headers, it is just the quickest and easiest way).
    Really shouldn't be hard to implement a row header and manually add it to the scroll panes row header area or use a BorderLayout and put your row header in the WEST and put your table in the CENTER if you don't want a scroll pane.
    Of course this won't help you with your printing issue.

  • Image in header of PDF - Web Template

    Hi guys,
    My client want's to have the company logo in header of PDF generated of web template how can i achieve the same.
    If i go through the Export wizard in the web template then i have limited options for header display wherein i can't set image in header. Is there any function's or something else which can help me to display image in header.
    Please help.

    You can create print versions of BI applications. To do this, you first export the selected Web application in PDF format. You can then print the PDF version. A dialog is provided to support you in creating print versions. You use this dialog to specify the layout of the print version.
    Note that when printing Web applications, it is only possible to export and print the following Web items:
    &#9679;      Analysis
    &#9679;      Chart
    &#9679;      Maps
    &#9679;      Report
    &#9679;      Information Field
    &#9679;      List of Exceptions
    &#9679;      List of Conditions
    &#9679;      Text
    You cannot print MIME objects or other Web items. If you want to print MIME objects (such as logos) that you have inserted into a Web template, you must insert the relevant MIME object into the Web application by using the Report Web item.

  • Printing JTable problem

    hi
    i have a problem in printing jtable
    after printing the box around the table only printed and the content of the table isn't
    instead there is a wight space in the box
    can any one help me

    In fact the program i'm making is for printing preview
    it's three classes i found in one of the topics , then i modified them to preview a table
    here is my code : \\ the class "TPrintPreview" needs a JTable object as an argument
    ********************************TPrintPreview.java************************************************************
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.awt.print.PageFormat;
    import java.awt.print.Paper;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import java.text.MessageFormat;
    import javax.swing.JTable;
    import javax.swing.JTable.PrintMode;
    * @author  TAREQ145
    public class TPrintPreview extends javax.swing.JFrame {
       int m_wPage;
       int m_hPage;
        /** Creates new form TPrintPreview */
        public TPrintPreview(JTable table) {
            initComponents();
            PageFormat m_pageFormat = PrinterJob.getPrinterJob().defaultPage();//use PageDialog
            m_wPage = (int)(m_pageFormat.getWidth());
            m_hPage = (int)(m_pageFormat.getHeight());
            int scale = getScale(5);  //Scale Index = 100
            jComboBox1.setSelectedIndex(5);
            int w = (int)(m_wPage*scale/100);
            int h = (int)(m_hPage*scale/100);   
            int pageIndex = 0;
            try{
            while (true) {
                int theFirstImageWidth = table.getColumnModel().getTotalColumnWidth()+1;
                BufferedImage img = new BufferedImage(theFirstImageWidth, theFirstImageWidth+180, BufferedImage.TYPE_INT_RGB); 
                Graphics g = img.getGraphics();
                g.setColor(Color.white);
                g.fillRect(0, 0, theFirstImageWidth , theFirstImageWidth+180);//180 = height - width
                Paper p = new Paper();
                p.setImageableArea(0,0,theFirstImageWidth,theFirstImageWidth+180);
                m_pageFormat.setPaper(p);
                Printable  m_target = table.getPrintable(PrintMode.FIT_WIDTH,null,new MessageFormat("- {0} -"));
               if (m_target.print(g, m_pageFormat, pageIndex) != Printable.PAGE_EXISTS) {
                   img = null;
                   break;
                int rightOrLeftSpace = 25;
                int upOrDownSpace = 25;
                int theSecondImageWidth = theFirstImageWidth + (rightOrLeftSpace*2);
                BufferedImage img2 = new BufferedImage(theSecondImageWidth, theSecondImageWidth+180, BufferedImage.TYPE_INT_RGB); 
                Graphics g2 = img2.getGraphics();
                g2.setColor(Color.white);
                g2.fillRect(0, 0, theSecondImageWidth, theSecondImageWidth+180);
                g2.drawImage(img,rightOrLeftSpace,upOrDownSpace,null); 
                Image img3 = img2.getScaledInstance(m_wPage,m_hPage,Image.SCALE_SMOOTH);
                PagePreview pp = new PagePreview(w, h, img3);
                previewContainer1.add(pp);
                //pp = null;
                pageIndex++;
                img = null;
                g = null;
            } catch (PrinterException e)   {
              e.printStackTrace();
             System.err.println("Printing error: "+e.toString());
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            previewContainer1 = new PreviewContainer();
            jButton1 = new javax.swing.JButton();
            jComboBox1 = new javax.swing.JComboBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("Print Preview");
            jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
            jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel1.setText("Print Preview");
            jLabel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
            javax.swing.GroupLayout previewContainer1Layout = new javax.swing.GroupLayout(previewContainer1);
            previewContainer1.setLayout(previewContainer1Layout);
            previewContainer1Layout.setHorizontalGroup(
                previewContainer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 752, Short.MAX_VALUE)
            previewContainer1Layout.setVerticalGroup(
                previewContainer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 511, Short.MAX_VALUE)
            jScrollPane1.setViewportView(previewContainer1);
            jButton1.setText("EXIT");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10 %", "25 %", "30 %", "50 %", "75 %", "100 %", "125 %", "150 %", "175 %", "200 %" }));
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 754, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 754, Short.MAX_VALUE))
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(183, 183, 183)
                            .addComponent(jButton1)
                            .addGap(74, 74, 74))))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(40, 40, 40)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(80, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            this.dispose();
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
            int scale = getScale(jComboBox1.getSelectedIndex());
                      int w = (int)(m_wPage*scale/100);
                      int h = (int)(m_hPage*scale/100);
                      Component[] comps = previewContainer1.getComponents();
                      for (int k=0; k<comps.length; k++) {
                         if (!(comps[k] instanceof PagePreview)) continue;
                         PagePreview pp = (PagePreview)comps[k];
                         pp.setScaledSize(w, h);
                      previewContainer1.doLayout();
                      getContentPane().validate();
        private int getScale(int scaleIndex) {
          int scale = 10;
          String[] scales = { "10 %", "25 %", "30 %", "50 %", "75 %", "100 %" , "125 %","150 %","175 %","200 %"};
          if (scaleIndex>-1 && scaleIndex<scales.length) {
             String str = scales[scaleIndex];
             if (str.endsWith("%"))str = str.substring(0, str.length()-1);
             str = str.trim();
             try { scale = Integer.parseInt(str); }
             catch (NumberFormatException ex) { ex.printStackTrace();}
          return scale;
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JScrollPane jScrollPane1;
        private PreviewContainer previewContainer1;
        // End of variables declaration                  
    ********************************PreviewContainer.java************************************************************
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Insets;
    import javax.swing.JPanel;
    * PreviewContainer.java
    * Created on 04 &#1603;&#1575;&#1606;&#1608;&#1606; &#1575;&#1604;&#1579;&#1575;&#1606;&#1610;, 2008, 10:20 &#1605;
    * @author  TAREQ145
    public class PreviewContainer extends JPanel {
        protected int H_GAP = 16;
        protected int V_GAP = 10;
        /** Creates new form BeanForm */
        public PreviewContainer() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
        }// </editor-fold>                       
          public Dimension getPreferredSize() {
             int n = getComponentCount();
             if (n == 0) return new Dimension(H_GAP, V_GAP);
             Component comp = getComponent(0);
             Dimension dc = comp.getPreferredSize();
             Dimension dp = getParent().getSize();
             int nCol = Math.max((dp.width - H_GAP) / (dc.width + H_GAP), 1);
             int nRow = n / nCol;
             if ((nRow * nCol) < n) nRow++;
             int ww = nCol * (dc.width + H_GAP) + H_GAP;
             int hh = nRow * (dc.height + V_GAP) + V_GAP;
             Insets ins = getInsets();
             return new Dimension(ww+ins.left+ins.right, hh+ins.top+ins.bottom);
          public Dimension getMaximumSize() {
             return getPreferredSize();
          public Dimension getMinimumSize() {
             return getPreferredSize();
          public void doLayout() {
             Insets ins = getInsets();
             int x = ins.left + H_GAP;
             int y = ins.top + V_GAP;
             int n = getComponentCount();
             if (n == 0) return;
             Component comp = getComponent(0);
             Dimension dc = comp.getPreferredSize();
             int w = dc.width;
             int h = dc.height;
    //fl+ 03.09.2003
             if (getParent() == null) return;
    //fl-        
             Dimension dp = getParent().getSize();
             int nCol = Math.max((dp.width-H_GAP)/(w+H_GAP), 1);
             int nRow = n/nCol;
             if (nRow*nCol < n) nRow++;
             int index = 0;
             for (int k = 0; k<nRow; k++) {
                for (int m = 0; m<nCol; m++) {
                   if (index >= n) return;
                   comp = getComponent(index++);
                   comp.setBounds(x, y, w, h);
                   x += w+H_GAP;
                y += h+V_GAP;
                x = ins.left + H_GAP;
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    ******************************PagePreview.java***********************************************************************************
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Insets;
    import javax.swing.JPanel;
    * PagePreview.java
    * Created on 04 &#1603;&#1575;&#1606;&#1608;&#1606; &#1575;&#1604;&#1579;&#1575;&#1606;&#1610;, 2008, 10:25 &#1605;
    import javax.swing.border.MatteBorder;
    * @author  TAREQ145
    public class PagePreview extends JPanel {
         protected int m_w;
         protected int m_h;
         protected Image m_source;
         protected Image m_img;
        /** Creates new form BeanForm */
        public PagePreview() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
        }// </editor-fold>                       
        public PagePreview(int w, int h, Image source) {
             m_w = w;
             m_h = h;
             m_source = source;
             m_img = m_source.getScaledInstance(m_w, m_h, Image.SCALE_SMOOTH);
             m_img.flush();
             setBackground(Color.white);
             setBorder(new MatteBorder(1, 1, 2, 2, Color.black));
          public void setScaledSize(int w, int h) {
             m_w = w;
             m_h = h;
             m_img = m_source.getScaledInstance(m_w, m_h, Image.SCALE_SMOOTH);
             repaint();
          public Dimension getPreferredSize() {
             Insets ins = getInsets();
             return new Dimension(m_w+ins.left+ins.right,
                m_h+ins.top+ins.bottom);
          public Dimension getMaximumSize() {
             return getPreferredSize();
          public Dimension getMinimumSize() {
             return getPreferredSize();
          public void paint(Graphics g) {
             g.setColor(getBackground());
             g.fillRect(0, 0, getWidth(), getHeight());
             g.drawImage(m_img, 0, 0, this);
             paintBorder(g);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    }please help me
    thankz

  • How can I insert and image in all PDFs printed via BW?

    How can I insert and image in all PDFs printed via BW?
    We want to remove the image from all Web Templates and insert it in the header of PDF printouts.
    <removed by moderator>!
    Tom
    Edited by: Siegfried Szameitat on Dec 3, 2008 2:57 PM

    Select clip in timeline. Open effects. At the bottom, search for flip. This should find the "Flipped" effect. Drag that effect cover the clip.

  • Printing JTable SOS

    Hi , Iknow... this is an question very request... but... What can say . I NEED HEL P
    I need printing JTABLE LANDSCAPE here my code example ...
    Thank you.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import com.sun.java.swing.*;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.OrientationRequested;
    import javax.swing.*;
    public class printpanel extends JPanel implements ActionListener, Printable {
    public printpanel() {
         setBackground(Color.white);
    JButton b = new JButton("MyButton");
    b.addActionListener(this);
    add(b);
         JLabel tit = new JLabel ("Liquidaci�n M�dico");
              tit.setFont( new Font( "Helvetica",Font.BOLD,16 ) );
              tit.setForeground(Color.black);
              setBackground(Color.white);
              add(tit);     
    //array bidimencional de objetos con los datos de la tabla
    final Object[][] data = {
    {"Mary", "Campione", "Esquiar", new Integer(5), new Boolean(false)},
    {"Lhucas", "Huml", "Patinar", new Integer(3), new Boolean(true)},
    {"Kathya", "Walrath", "Escalar", new Integer(2), new Boolean(false)},
    {"Marcus", "Andrews", "Correr", new Integer(7), new Boolean(true)},
    {"Angela", "Lalth", "Nadar", new Integer(4), new Boolean(false)}
    //array de String's con los t�tulos de las columnas
    final String[] columnNames = {"Nombre", "Apellido", "Pasatiempo",
    "A�os de Practica", "Soltero(a)"};
    //se crea la Tabla
    final JTable table = new JTable(data, columnNames);
    // table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setSelectionBackground( Color.red );
    //Creamos un JscrollPane y le agregamos la JTable
    final JScrollPane scrollPane = new JScrollPane(table);
         add(scrollPane);
    public void actionPerformed(ActionEvent e) {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    PageFormat a = new PageFormat();
    try { printJob.print(); } catch (Exception PrintException) { }
    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2d= (Graphics2D)g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());
    Font f = new Font("Monospaced",Font.PLAIN,12);
         g2d.setFont (f);
         paint (g);
    return Printable.PAGE_EXISTS;
    public static void main(String s[]) {
         WindowListener l = new WindowAdapter() {
         public void windowClosing(WindowEvent e) {System.exit(0);}
         Frame f = new Frame("Imprimir");
         f.addWindowListener(l);
         f.add("Center", new printpanel());
         //f.pack();
         f.setSize(new Dimension(500,300));
         f.show();
    }

    Hai!,
    I am posting this code for the request i received from the mfwjava-person by mail. The below modified code works well.
    I Used ORACLE ODBC* since it only supports more query features of sql statements and your select *... statement works well in this only. I didn't checked the print - out. But our senior Mr.URHAND checked it(Thank him).
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Rectangle2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.print.attribute.*;
    import javax.print.*;
    import javax.print.attribute.standard.*;
    import javax.print.attribute.standard.MediaSize;
    import java.sql.Connection;
    import java.sql.*;
    import java.text.MessageFormat;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.*;
    public class Grafica extends JPanel implements ActionListener {
    JTable table=new JTable();
    public static JScrollPane scrollPane;
    public Grafica() {
    JButton b = new JButton("Imprimir");
    b.addActionListener(this);
    add(b);
    JLabel tit = new JLabel("Liquidaci�n M�dico");
    tit.setFont( new Font( "Helvetica",Font.BOLD,16 ) );
    tit.setForeground(Color.black);
    setBackground(Color.white);
    add(tit);
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:Sego", "scott", "tiger");
    DriverManager.setLogStream(System.out);
    Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery("SELECT Medico_opera,Descip_Item,Codigo_estudio,Count(Descip_Item),Sum(Liquid_opera) FROM Datos Group By Medico_opera,Descip_Item,Codigo_estudio ");
    rs=statement.getResultSet();
    String[] columnas = {"M�dico","Descripci�n Item","Codigo nr.","Total de Items","Total M�dico Op."};
    JTable table =rsInTable(rs);
    scrollPane = new JScrollPane(table);
    add(scrollPane);
    statement.close();
    con.close();
    } catch (SQLException sqle) {
    sqle.printStackTrace();
    } catch (Exception ed) {
    ed.printStackTrace();
    public void actionPerformed(ActionEvent e) {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable( new TableReport(table,
    new MessageFormat("Liquidaci�n M�dico"), null) );
    try{
    PrinterJob prnJob = PrinterJob.getPrinterJob();
         PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
         //aset.add(new Copies(2));
         //aset.add(new MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4));
    //aset.add(MediaName.ISO_A4_WHITE);
         aset.add(MediaSizeName.ISO_A4);
         aset.add(Sides.ONE_SIDED);
         aset.add(OrientationRequested.LANDSCAPE);//------>HERE IT IS
         if (!prnJob.printDialog(aset))return;
         //aset.add(MediaName.ISO_A4_TRANSPARENT);
    setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    prnJob.print();
    setCursor( Cursor.getPredefinedCursor(
    Cursor.DEFAULT_CURSOR));
    }catch (Exception PrintException) {}
    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2d= (Graphics2D)g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());
    Font f = new Font("Monospaced",Font.PLAIN,12);
    g2d.setFont(f);
    paint(g);
    return Printable.PAGE_EXISTS;
    public static void main(String s[]) {
    WindowListener l = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    Frame f = new Frame("Imprimir");
    f.addWindowListener(l);
    f.add("Center", new Grafica());
    f.setSize(new Dimension(500,300));
    f.show();
    public JTable rsInTable(ResultSet rs)throws SQLException{
    JTable table;
    boolean moreRecords=rs.next();
    table=new JTable(0,0);
    Vector colh=new Vector();
    Vector rows=new Vector();
    try{
    ResultSetMetaData rsmd=rs.getMetaData();
    for(int i=1;i<=rsmd.getColumnCount();++i)
    colh.addElement(rsmd.getColumnName(i));
    System.out.println(String.valueOf(rs.getRow()));
    while(rs.next()){
    rows.addElement(getNextRow(rs,rsmd));
    table=new JTable(rows,colh);
    catch(SQLException e2)
    e2.printStackTrace();
    if(!moreRecords)
    return table;
    return table;
    private Vector getNextRow(ResultSet rs,ResultSetMetaData rsmd)throws SQLException
    Vector crow=new Vector();
    for(int i=1;i<=rsmd.getColumnCount();++i)
    switch(rsmd.getColumnType(i))
    case Types.VARCHAR:
    crow.addElement(rs.getString(i));
    break;
    case Types.INTEGER:
    crow.addElement(new Long(rs.getLong(i)));
    break;
    case Types.DOUBLE:
    crow.addElement(new Double(rs.getDouble(i)));
    break;//----> HERE U ADD OTHER TYPES - U NEED?
    default:
    crow.addElement(new String(rs.getString(i)));
    System.out.println("type was: "+rsmd.getColumnTypeName(i));
    break;
    return crow;
    class TableReport implements Printable {
    private JTable table;
    private JTableHeader header;
    private TableColumnModel colModel;
    private int totalColWidth;
    private MessageFormat headerFormat;
    private MessageFormat footerFormat;
    private int last = -1;
    private int row = 0;
    private int col = 0;
    private final Rectangle clip = new Rectangle(0, 0, 0, 0);
    private final Rectangle hclip = new Rectangle(0, 0, 0, 0);
    private final Rectangle tempRect = new Rectangle(0, 0, 0, 0);
    private static final int H_F_SPACE = 8;
    private static final float HEADER_FONT_SIZE = 18.0f;
    private static final float FOOTER_FONT_SIZE = 12.0f;
    private Font headerFont;
    private Font footerFont;
    public TableReport(JTable table,
    MessageFormat headerFormat,
    MessageFormat footerFormat) {
    this.table = table;
    header = table.getTableHeader();
    colModel = table.getColumnModel();
    totalColWidth = colModel.getTotalColumnWidth();
    if (header != null) {
    hclip.height = header.getHeight();
    this.headerFormat = headerFormat;
    this.footerFormat = footerFormat;
    headerFont = table.getFont().deriveFont(Font.BOLD,
    HEADER_FONT_SIZE);
    footerFont = table.getFont().deriveFont(Font.PLAIN,
    FOOTER_FONT_SIZE);
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
    throws PrinterException {
    final int imgWidth = (int)pageFormat.getImageableWidth();
    final int imgHeight = (int)pageFormat.getImageableHeight();
    if (imgWidth <= 0) {
    throw new PrinterException("Width of printable area is too small.");
    Object[] pageNumber = new Object[]{new Integer(pageIndex + 1)};
    String headerText = null;
    if (headerFormat != null) {
    headerText = headerFormat.format(pageNumber);
    String footerText = null;
    if (footerFormat != null) {
    footerText = footerFormat.format(pageNumber);
    Rectangle2D hRect = null;
    Rectangle2D fRect = null;
    int headerTextSpace = 0;
    int footerTextSpace = 0;
    int availableSpace = imgHeight;
    if (headerText != null) {
    graphics.setFont(headerFont);
    hRect = graphics.getFontMetrics().getStringBounds(headerText,
    graphics);
    headerTextSpace = (int)Math.ceil(hRect.getHeight());
    availableSpace -= headerTextSpace + H_F_SPACE;
    if (footerText != null) {
    graphics.setFont(footerFont);
    fRect = graphics.getFontMetrics().getStringBounds(footerText,
    graphics);
    footerTextSpace = (int)Math.ceil(fRect.getHeight());
    availableSpace -= footerTextSpace + H_F_SPACE;
    if (availableSpace <= 0) {
    throw new PrinterException("Height of printable area is too small.");
    double sf = 1.0D;
    if ( totalColWidth > imgWidth) {
    sf = (double)imgWidth / (double)totalColWidth;
    while (last < pageIndex) {
    if (row >= table.getRowCount() && col == 0) {
    return NO_SUCH_PAGE;
    int scaledWidth = (int)(imgWidth / sf);
    int scaledHeight = (int)((availableSpace - hclip.height) / sf);
    findNextClip(scaledWidth, scaledHeight);
    last++;
    Graphics2D g2d = (Graphics2D)graphics;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    AffineTransform oldTrans;
    if (footerText != null) {
    oldTrans = g2d.getTransform();
    g2d.translate(0, imgHeight - footerTextSpace);
    printText(g2d, footerText, fRect, footerFont, imgWidth);
    g2d.setTransform(oldTrans);
    if (headerText != null) {
    printText(g2d, headerText, hRect, headerFont, imgWidth);
    g2d.translate(0, headerTextSpace + H_F_SPACE);
    tempRect.x = 0;
    tempRect.y = 0;
    tempRect.width = imgWidth;
    tempRect.height = availableSpace;
    g2d.clip(tempRect);
    if (sf != 1.0D) {
    g2d.scale(sf, sf);
    } else {
    int diff = (imgWidth - clip.width) / 2;
    g2d.translate(diff, 0);
    oldTrans = g2d.getTransform();
    Shape oldClip = g2d.getClip();
    if (header != null) {
    hclip.x = clip.x;
    hclip.width = clip.width;
    g2d.translate(-hclip.x, 0);
    g2d.clip(hclip);
    header.print(g2d);
    g2d.setTransform(oldTrans);
    g2d.setClip(oldClip);
    g2d.translate(0, hclip.height);
    g2d.translate(-clip.x, -clip.y);
    g2d.clip(clip);
    table.print(g2d);
    g2d.setTransform(oldTrans);
    g2d.setClip(oldClip);
    g2d.setColor(Color.BLACK);
    g2d.drawRect(0, 0, clip.width, hclip.height + clip.height);
    return PAGE_EXISTS;
    private void printText(Graphics2D g2d,
    String text,
    Rectangle2D rect,
    Font font,
    int imgWidth) {
    int tx;
    if (rect.getWidth() < imgWidth) {
    tx = (int)((imgWidth - rect.getWidth()) / 2);
    } else if (table.getComponentOrientation().isLeftToRight()) {
    tx = 0;
    } else {
    tx = -(int)(Math.ceil(rect.getWidth()) - imgWidth);
    int ty = (int)Math.ceil(Math.abs(rect.getY()));
    g2d.setColor(Color.BLACK);
    g2d.setFont(font);
    g2d.drawString(text, tx, ty);
    private void findNextClip(int pw, int ph) {
    final boolean ltr = table.getComponentOrientation().isLeftToRight();
    if (col == 0) {
    if (ltr) {
    clip.x = 0;
    } else {
    clip.x = totalColWidth;
    clip.y += clip.height;
    clip.width = 0;
    clip.height = 0;
    int rowCount = table.getRowCount();
    int rowHeight = table.getRowHeight(row);
    do {
    clip.height += rowHeight;
    if (++row >= rowCount) {
    break;
    rowHeight = table.getRowHeight(row);
    } while (clip.height + rowHeight <= ph);
    clip.x = 0;
    clip.width = totalColWidth;
    * ALWAYS POST IN THIS FORUMS
    *I ALWAYS LIKE TO REPLY IN THIS FORUM.SO PLEASE!!!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • In ALV Report output heading is printing twice.

    Hi Experts,
    Im working on ALV Reports.
    Im printing header text by using listheader and commentary write function module.
    the problem is when i sort any column in ALV ouput the heading is printing twice.
    Again if i sort the column the heading is printed is 4 times.
    so if anybody knows the solution how we can avoid repetition of heading ,
    Please reply me as soon as possible.
    regards
    Imrangs.

    Hi Noorie,
    Thanks a lot.
    Your answer is perfect.
    Bye.
    Regards,
    Imran

  • Web Analysis report is not coming with the border/logo/heading while print

    Hi All,
    I am using 9.3.1 version of hyperion planning were Web Analysis report is not coming with the border/logo/heading while printing with the option "print all object", Only the data grid is coming in the print. If I use "print screen" it is coming with border/logo/heading but it gives a screenshot of the report, that won't cater out need.
    So please suggest us with a resolution to have border, logo and heading, while using Print all object.
    Thanks with regards....
    Rao

    Hi Sagar,
    In scripts when you will see print preview the logo will be not shown up with clarity.Take the print out of the document and check whether logo is printing up with clarity.
    Thanks
    Phani

  • Is it possible to print JTable and custom JPanel on the same page?

    Hello everybody!
    I have a custom panel extending JPanel and implementing Printable.
    I am using paint() method to draw some graphics on it's content pane. I would like to print it, but first I would like to add a JTable at the bottom of my panel. Printing just the panel goes well. No problems with that.
    I was also able to add a JTable to the bottom of JFrame, which contains my panel.
    But how can I print those two components on one page?

    Hi, thanks for your answer, but I thought about that earlier and that doesn't work as well... or mybe I'm doing something wrong. Here is the sample code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    public class ReportFrame extends JFrame implements Printable {
         private static final long serialVersionUID = -8291124097290245799L;
         private MyPanel rp;
         private JTable reportTable;
         private HashPrintRequestAttributeSet attributes;
         public ReportFrame() {
              rp = new MyPanel();
              String[] columnNames = { "Column1", "Column2", "Column3" };
              String[][] values = { { "Value1", "Value2", "Value3" }, { "Value4", "Value5", "Value6" }, { "Value7", "Value8", "Value9" } };
              reportTable = new JTable(values, columnNames);
              add(rp, BorderLayout.CENTER);
              add(reportTable, BorderLayout.SOUTH);
              setTitle("Printing example");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setPreferredSize(new Dimension(700, 700));
              pack();
              setVisible(true);
         @Override
         public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
              if (pageIndex >= 1)
                   return Printable.NO_SUCH_PAGE;
              Graphics2D g2D = (Graphics2D) graphics;
              g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
              return Printable.PAGE_EXISTS;
         public static void main(String[] args) {
              new ReportFrame().printer();
         class MyPanel extends JPanel implements Printable {
              private static final long serialVersionUID = -2214177603101440610L;
              @Override
              public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
                   if (pageIndex >= 1)
                        return Printable.NO_SUCH_PAGE;
                   Graphics2D g2D = (Graphics2D) graphics;
                   g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                   return Printable.PAGE_EXISTS;
              @Override
              public void paint(Graphics g) {
                   super.paintComponent(g);
                   Graphics2D g2D = (Graphics2D) g;
                   int x = 0, y = 0, width = 70, height = 70;
                   for (int i = 0; i < 50; i++) {
                        g2D.drawOval(x + i * 10, y + i * 10, width, height);
         public void printer() {
              try {
                   attributes = new HashPrintRequestAttributeSet();
                   PrinterJob job = PrinterJob.getPrinterJob();
                   job.setPrintable(this);
                   if (job.printDialog(attributes))
                        job.print(attributes);
              } catch (PrinterException e) {
                   JOptionPane.showMessageDialog(this, e);
    }UPDATE:
    I've managed to get this to work, by calling 2 methods inside the outer frame's print method (lines 78 and 79)
    Those two methods are:
    rp.paint(g2D);
    reportTable.paint(g2D);but still it is not the way I would like it to be.
    First of all both the ReportPanel and ReportTable graphics are printed with the upper-left corner located in the upper-left corner of the JFrame and the first one is covering the second.
    Secondly, I would like to rather implemet the robust JTable's print method somehow, because it has some neat features like multipage printing, headers & footers. But I have no idea how to add my own graphics to the JTables print method, so they will appear above the JTable. Maybe someone knows the answer?
    Thanks a lot
    UPDATE2:
    I was googling nearly all day in search of an answer, but with no success. I don't think it's possible to print JTable using it's print() method together with other components, so I will have to think of something else i guess...
    Edited by: Adalbert23 on Nov 22, 2007 2:49 PM

  • Converting Images to CMYK for Print Publication

    When in my workflow should I be converting images to CMYK for print publication?
    Currently, I shoot RAW photographs with my DSLR in Adobe RGB, import the images into Photoshop for manipulation and then convert the final, sized image to CMYK before placing it in my Indesign document. Before going to print, I convert my files to PDF using the [PDF/X-1a:2001] preset. I use a calibrated system with a profile set for my monitor.
    Since many of my pictures have shades of green, I'm often disappointed with the conversion to CMYK because I lose saturation and brightness. Am I doing anything wrong? Is there a better way of preserving the quality of colour in my images when going to a commercial printer?

    To see in InDesign what color shifts will occur, use View=>Proof Colors.
    I would also recommend View=>Overprint Preview.
    Yes there are color shifts when converting RGB to CMYK, but those are due to the fact that the gamut of CMYK is significantly less than AdobeRGB or even sRGB. The same color shifts going to CMYK will occur whether you convert the image in Photoshop or in InDesign during PDF export or at the RIP.
    Keeping the color in ICC color managed RGB has the advantage that last minute changes can be made as to what CMYK printing conditions are used, i.e. all CMYK is not the same. Furthermore, if you convert RGB to CMYK early in the workflow, you lose the ability to maintain the color gamut for display of the PDF as well as for printing to high fidelity color devices, i.e., offset or digital (especially inkjet) devices that have extra colorants such as light cyan, light magenta, orange, and/or green to dramatically expand the gamut. Once you lose the gamut in your imagery via conversion to CMYK, you can't go back.
              - Dov

Maybe you are looking for

  • Can i upgrade exchange 2007 to exchange 2013 on same small business server 2008 machine?

    Hi, I have small business server 2008 with exchange 2007 installed in my organization, Now I need to upgrade exchange 2007 to exchange 2013 on same small business server 2008 standard edition. I already tried to upgrade but not successful. can i upgr

  • Writing a plugin for Weblogic

    Hi, Is it possible to add a mechanism to Weblogic which would intercept EJB lookups and requests (on a per bean and per method basis), and perform custom access control logic? This mechanism should be seamless and transparent to client code so that e

  • "Your Mac OS X Startup Disk Has No More Space For Application Memory"

    I've been having a problem in the last few days with my Mac. I would be surfing the net, or doing whatever, and an error message would randomly pop up on my screen. It would say: "_Your Mac OS X Startup Disk Has No More Space For Application Memory_"

  • Tip message in various languages

    Hello all, We are implementing Self Service in spain. We need to specify a custom tip message. I have created application message AM1 with language as US and also E so that when the user changes the session language to Spain, he/she can see the messa

  • How to run java progarm like jbuilder in windows

    hi, I had writed a java program with JBuilder6. After i deploy it, I can only run it in the DOS window using command line in the windows OS, and when it is running , there is always a DOS window opened. JBuilder6 is a pure java program, but when it i