Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



How to Print Tables using Swings in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-02-2010
Member
 
Join Date: Jul 2006
Posts: 283
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..
Reply With Quote
  #2  
Old 16-02-2010
Warner's Avatar
Member
 
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.
Reply With Quote
  #3  
Old 16-02-2010
Allan.d's Avatar
Member
 
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) {
    ...
}
Reply With Quote
  #4  
Old 16-02-2010
Member
 
Join Date: Nov 2008
Posts: 997
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);
Reply With Quote
  #5  
Old 16-02-2010
Viensterrr's Avatar
Member
 
Join Date: Jul 2006
Posts: 232
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
Reply With Quote
  #6  
Old 16-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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;
        }
    }
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Print Tables using Swings in Java?"
Thread Thread Starter Forum Replies Last Post
How to use Tables in Java? Rob Dizzle Software Development 4 11-02-2010 07:04 AM
Reading tables in java.io Miles Runner Software Development 5 20-01-2010 10:30 AM
Print JTable with the help of java Coldman Software Development 3 25-11-2009 09:02 AM
Print in java using Swing Sheenas Software Development 3 18-11-2009 09:50 AM
Creating Tables in Java RockOn Software Development 3 09-04-2009 11:57 PM


All times are GMT +5.5. The time now is 11:13 AM.