This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
JTable printing . . .
Sanjeev Charla
Ranch Hand
Joined: Apr 02, 2009
Posts: 90
I like...
posted
May 11, 2011 01:40:48
0
import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.text.MessageFormat; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class MainClass { public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Print"); ActionListener printAction = new ActionListener() { public void actionPerformed(ActionEvent e) { try { MessageFormat headerFormat = new MessageFormat("Page {0}"); MessageFormat footerFormat = new MessageFormat("- {0} -"); table.print(JTable.PrintMode.FIT_WIDTH, headerFormat, footerFormat); } catch (PrinterException pe) { System.err.println("Error printing: " + pe.getMessage()); } } }; button.addActionListener(printAction); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 150); frame.setVisible(true); } }
and here is the screenshot of output file printed
with out headers and footers
how to print these headers and footers ??
thanks
NoHeadersFooters.png
Headers and footers are missing . . . why ??
I agree. Here's the link:
http://aspose.com/file-tools
subject: JTable printing . . .
Similar Threads
JTable ........
Grid header for JTable
JTable
jtable
Printing invicible JTable with Column removed - JTable.PrintMode.FIT_WIDTH problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter