Results 1 to 6 of 6
Thread: help with printing a JTable
- 09-04-2011, 07:15 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
help with printing a JTable
I need help printing a JTable, i used the .print() method, but when i do that, it prints a empty rectangle, this is my code right here:
Am i doing something wrong here?Java Code:package jtable; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.print.PrinterException; import java.text.MessageFormat; import javax.swing.*; public class table extends JFrame{ /** * @param args */ JTable table; public static void main(String[] args) { table gui = new table(); gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setSize(600, 200); gui.setTitle("Table test"); gui.setVisible(true); } public table(){ setLayout( new FlowLayout() ); String[] columnNames = {"Naam", "Achternaam", "Geboorte jaar"}; Object[] [] data = { {"Freek", "van der Toorn", "1993"}, {"Jesse", "Frerichs", "1993"} }; table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 50)); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); MessageFormat header = new MessageFormat("Page {0,number,integer}"); try { table.print(JTable.PrintMode.FIT_WIDTH, header, null); } catch (PrinterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
I hope you guys can help me
- 09-04-2011, 11:04 PM #2
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
Re: help with printing a JTable
it just shows the outlines of a rectangle, about half the width of a A4 piece of paper and at the top op the page in the center
- 09-04-2011, 11:13 PM #3
Re: help with printing a JTable
Are you printing before the table has been displayed in the GUI?
- 09-04-2011, 11:17 PM #4
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
Re: help with printing a JTable
it says so in the code, first i create the JTable, then i add its content, and then i add the JTable to the screen and lastly i try to print it
- 09-04-2011, 11:19 PM #5
Re: help with printing a JTable
But it hasn't be set visible yet. Add code to do the print AFTER the GUI is visible.
- 09-05-2011, 04:38 AM #6
Similar Threads
-
Help with printing an arrayList. printing the first element twice
By kingkongjaffa in forum New To JavaReplies: 9Last Post: 08-19-2011, 12:59 AM -
JTable printing with larger fonts
By Singing Boyo in forum New To JavaReplies: 0Last Post: 07-07-2011, 08:31 AM -
printing string backwards and printing every other
By droidus in forum New To JavaReplies: 22Last Post: 03-10-2011, 09:17 AM -
printing large jtable
By j2me64 in forum Advanced JavaReplies: 1Last Post: 04-27-2010, 02:46 PM -
Problem in printing JTable values
By shanssat in forum AWT / SwingReplies: 3Last Post: 02-04-2009, 08:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks