java - Printing a Jtable as Table into file -


i in process of creating application finance management.so trying final job getting summary printed. ths summary page consists of different tables , each followed 2 labels , text field. great if can me light this.

all want print populated jtable onto file is.

i not expert java , im using netbeans coding gui.

also regarding fileformat think has .rtf supporting lines etc.hope there wont difficulty in creating rtf file this.

ps: im not particular format .rtf want format can support columns , tables.

one more thing wanted add want create receipts custom templates.i thinking of using .rtf files templates , adding neccessary values file. after editing file in java, doesnt seem looking fine. better if suggest me suitable format

edit:

ive managed readymade code printing jtable pdf , it's working , good. code follows

document document = new document(pagesize.a4); try { pdfwriter writer = pdfwriter.getinstance(document, new fileoutputstream("c:\users\arun\desktop\jtable.pdf"));

  document.open();    pdfcontentbyte cb = writer.getdirectcontent();    cb.savestate();   graphics2d g2 = cb.creategraphicsshapes(500, 500);    shape oldclip = g2.getclip();   g2.cliprect(0,0, 500, 500);    table.print(g2);   g2.setclip(oldclip);    g2.dispose();   cb.restorestate();   joptionpane.showmessagedialog(null,"done","done",joptionpane.information_message); } catch (exception e) {   system.err.println(e.getmessage()); } document.close(); 

but table being printed close left side of page.i wanted leave left margin , heading of each table column printed.

i tried document.setmargins() .but not working. regarding headings of column, have not clue.

you can pull out data retrieving tablemodel jtable via jtable.getmodel(), iterate on contents using model.getrowcount(), model.getcolumncount() , model.getvalueat(row, col), , print values ordinary filewriter if don't want 3rd party tools.

see jtable, tablemodel, filewriter, bufferedwriter in api docs.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -