Sasha
Sasha

Reputation: 29

I need to print a JTextArea and a JTable on the same page.

I am trying to print a jtable and jtextarea on the same page. I have tried this so far

private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
// TODO add your handling code here:


JTextArea detailArea = new JTextTable();        
JTable detailTable = new JTable();


    int page = 1;
    MessageFormat mf = new MessageFormat(detailArea.getText()));
    MessageFormat mf2 = new MessageFormat(Integer.toString(page));
page++;

try

    {
        detailTable.print(JTable.PrintMode.FIT_WIDTH,mf,mf2);
    }

    catch(PrinterException p)

    {
        JOptionPane.showMessageDialog(null,"Printer Exception");
    }    

}  

This is a bad solution as it prints the text of the textarea as a bold header. I need a method to print the Jtable with text above it on the same page.

Any help?

Thank you.

Upvotes: 0

Views: 2061

Answers (1)

trashgod
trashgod

Reputation: 205785

The article How to Print Tables may give you some ideas on how to construct your sscce.

  • Use getPrintable() to obtain a Printable from both the JTextArea and JTable; render each sequentially in your own implementation of Printable.

  • Override getPrintable() to decorate your table using the JTextArea content, as shown in TablePrintDemo3.

A java.awt.print.Book, outlined here, may be a useful way to organize your document.

Upvotes: 1

Related Questions