1

I want to Print JTABLE and A value from Text Field. Its like products detail and there Bill Print. Here is the image.

Required Print is Table + Total Amount,

But so far i got JTable.print() only print table. is there any way to add other values at end as total ??

Here is the code of printing jtable.

MessageFormat header = new MessageFormat("Purchases Bill {0,number,integer}");
                    try {
                        table.print(JTable.PrintMode.FIT_WIDTH, header, null);

                    } catch (java.awt.print.PrinterException e) {
                        System.err.format("Cannot print %s%n", e.getMessage());
                    }

enter image description here

Adnan Ali
  • 2,851
  • 5
  • 22
  • 39
  • Put what you want to print in a JPanel, then you can JPanel.print() – Gilbert Le Blanc Jan 24 '15 at 20:08
  • this whole stuff is in a jpanel but i just want to print one textfield not all – Adnan Ali Jan 24 '15 at 20:15
  • table.print(JTable.PrintMode.FIT_WIDTH, header, null); this dont work with Panel as well – Adnan Ali Jan 24 '15 at 20:19
  • You're going to have to resize the image anyway when you print to make sure it fits on the paper. – Gilbert Le Blanc Jan 24 '15 at 21:05
  • 1
    You'll have to write your own `Printable` which is capable of making space for your fields and then printing the `JTable` via it's own internal `Printable`, this is not a trivial process. Consider using something like JasperReports or some other reporting engine, which will make your life so much simper in the long run – MadProgrammer Jan 24 '15 at 21:23
  • @GilbertLeBlanc And when the image is to big to fit on a page? – MadProgrammer Jan 24 '15 at 21:23
  • Check out [this](http://stackoverflow.com/questions/26598472/printable-not-working-properly/26598867#26598867) for a crude example – MadProgrammer Jan 24 '15 at 21:24

1 Answers1

0

Use jtextfield1.print(); I think it will work. It will only print the specified textfield.

the
  • 21,007
  • 11
  • 68
  • 101
harsh
  • 1