|
| |||||||||
| Tags: fit_width, java, print, printdialog, swings, tables |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| |||
| |||
| 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
| ||||
| ||||
| 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 :
__________________ Signatures reduce available bandwidth |
|
#6
| ||||
| ||||
| 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;
}
}
__________________ Grand Theft Auto 4 PC Video Game |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |