Results 1 to 6 of 6

Thread: How to Print Tables using Swings in Java?

  1. #1
    Join Date
    Jul 2006
    Posts
    339

    How to Print Tables using Swings in Java?

    Hello Friends,
    I have done some basic coding in Swings. I have started doing the Java couple of months ago. Now I want to print tables. Should I use the JTable class or some other class should be used for printing the table..?? Please tell me how to Print Tables using Swings in Java? Expecting some help sooner.!! Thanks in Advance..

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: How to Print Tables using Swings in Java?

    Your guess was right.!! The JTable class provides support for printing tables. The method that allows you to implement both basic and advanced printing tasks is included in the JTable printing API. If you want to do some common printing, when you need to simply print a table, then you would have to use the print method directly. There are several forms with various argument set in the print method.

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: How to Print Tables using Swings in Java?

    By calling the print method without parameters is the easiest way to print your table. The following sample of code demonstrates the same :
    Code:
    try {
        boolean complete = table.print();
        if (complete) {
            ...
        } else {
            ...
        }
    } catch (PrinterException pe) {
        ...
    }

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: How to Print Tables using Swings in Java?

    Even I think that calling the print method without parameters is the easiest way to print your table. A print dialog is displayed when you call the print method with no parameters. After getting displayed a print dialog your table is printed interactively in the FIT_WIDTH mode. Also you should know that it gets printed without a header or a footer. The following code will explain you the print method signature with the complete set of arguments :
    Code:
    boolean complete = table.print(JTable.PrintMode printMode,
                                   MessageFormat footerFormat, 
                                   MessageFormat headerFormat,
                                   boolean showPrintDialog,
                                   PrintRequestAttributeSet attr,
                                   boolean interactive,
                                   PrintService service);

  5. #5
    Join Date
    Jul 2006
    Posts
    289

    Re: How to Print Tables using Swings in Java?

    There are two types of printing modes. Before that you should know about the printing mode. Printing modes are responsible for scaling the output and spreading it across pages. The two types of the printing modes are :
    • PrintMode.NORMAL
    • PrintMode.FIT_WIDTH

    In the NORMAL mode a table is printed at its current size. Even if the column is not fitting on a page then they spread across additional pages according to the table's ComponentOrientation.While in the FIT_WIDTH mode a table has a smaller size, if necessary, to fit all columns on each page.
    Signatures reduce available bandwidth

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to Print Tables using Swings in Java?

    The isPaintingForPrint method defined in the JComponent class allows us to customize what we print compared with that can be seen on the screen. Just have a look on following example which explains the same :
    Code:
    protected static class BWPassedColumnDemo extends PassedColumnDemo {
                public Component getTableCellDemoComponent(JTable table,
                                                               Object value,
                                                               boolean isSelected,
                                                               boolean hasFocus,
                                                               int row,
                                                               int column) {
    
                super.getTableCellDemoComponent(table, value, isSelected,
                                                    hasFocus, row, column);
    
                if (table.isPaintingForPrint()) {
                    boolean status = (Boolean)value;
                    setIcon(status ? passedIconBW : failedIconBW);
                }
    
                return this;
            }
        }

Similar Threads

  1. Will the check swings be fixed in MLB 2K12?
    By Sumeetay.Deol in forum Video Games
    Replies: 4
    Last Post: 06-03-2012, 04:25 PM
  2. How to use Tables in Java?
    By Rob Dizzle in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 07:04 AM
  3. Reading tables in java.io
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 10:30 AM
  4. Print in java using Swing
    By Sheenas in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 09:50 AM
  5. Creating Tables in Java
    By RockOn in forum Software Development
    Replies: 3
    Last Post: 09-04-2009, 10:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,454,275.38176 seconds with 17 queries