java - Jtable is not printing (blank document is printed) -


jtable table=somevalues;    table.print(jtable.printmode.fit_width,null,null,true,null,true,null); 

the print dialog box opening when print table not printed blank document printed. tell me going wrong? have **edited ** , code values is

string data[][]=new string[1][9];                     string head[]=new string[9];                      head[0]="date";                     head[1]="q1 rate per piece";                     head[2]="q1 total pieces";                     head[3]="q2 rate per piece";                     head[4]="q2 total pieces";                     head[5]="q3 rate per piece";                     head[6]="q3 total pieces";                     head[7]="total pieces";                     head[8]="total amount";                          data[0][0]="a";                         data[0][1]="b";                         data[0][2]="c";                         data[0][3]="d";                         data[0][4]="e";                         data[0][5]="f";                         data[0][6]="g";                         data[0][7]="h";                         data[0][8]="i";                      jtable table=new jtable(data,head);                 boolean complete=table.print(); 

solution 1

the easiest way print table call print method without parameters. see code example below.

try {     boolean complete = table.print();     if (complete) {         /* show success message  */         ...     } else {         /*show message indicating printing cancelled */         ...     } } catch (printerexception pe) {     /* printing failed, report user */     ... } 

when call print method no parameters, print dialog displayed, , table printed interactively in fit_width mode without header or footer. code example below shows print method signature complete set of arguments.

boolean complete = table.print(jtable.printmode printmode,                                messageformat headerformat,                                messageformat footerformat,                                 boolean showprintdialog,                                printrequestattributeset attr,                                boolean interactive,                                printservice service); 

when call print method arguments, explicitly choose printing features such printing mode, header , footer text, printing attributes, destination print service, , whether show print dialog or not, , whether print interactively or non-interactively. decide parameters suit needs best, see description of available features below.

the jtable printing api provides following features:

printing interactively or non-interactively displaying print dialog adding header or footer (or both) printing layout selecting printing mode automatic layout , pagination

solution 2

the following example print jtable

public jtable() jtable table = new jtable();  public jtable(int rows, int columns) jtable table = new jtable(2, 3);  public jtable(object rowdata[][], object columnnames[]) object rowdata[][] = { { "row1-column1", "row1-column2", "row1-column3"},                        { "row2-column1", "row2-column2", "row2-column3"} }; object columnnames[] = { "column one", "column two", "column three"}; jtable table = new jtable(rowdata, columnnames);  public jtable(tablemodel model) tablemodel model = new defaulttablemodel(rowdata, columnnames); jtable table = new jtable(model);  public jtable(tablemodel model, tablecolumnmodel columnmodel) tablecolumnmodel columnmodel = new defaulttablecolumnmodel(); tablecolumn firstcolumn = new tablecolumn(1); firstcolumn.setheadervalue(headers[1]);columnmodel.addcolumn(firstcolumn); tablecolumn secondcolumn = new tablecolumn(0); secondcolumn.setheadervalue(headers[0]); columnmodel.addcolumn(secondcolumn); jtable table = new jtable(model, columnmodel);  public jtable(tablemodel model, tablecolumnmodel columnmodel, listselectionmodel selectionmodel) listselectionmodel selectionmodel = new defaultlistselectionmodel(); selectionmodel.setselectionmode(listselectionmodel.single_selection); jtable table = new jtable(model, columnmodel, selectionmodel); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -