ola,

i need help fast plz, the printing function in java .print() works i.e.

jtextarea.print();

the problem is, if the jtextarea is longer than 1 page it will print the extra pages on some computers and not on others. I thought it a printer setting, but when the jtextarea is longer than 1 page and prompts the user to print the jtextarea it only detects 1 page on those computers...why? how do i fix this plzzzz?

krefie

Recommended Answers

All 3 Replies

soz, this is the code i use

try
        {
            boolean complete = txtAfvoer.print();
            
            if (complete)
            {//show a success message
                JOptionPane.showMessageDialog(new JFrame(), "Printing Page\n" + "Please click finish after printing", "Finished",JOptionPane.INFORMATION_MESSAGE);
                btnFinish.setEnabled(true);
            }
            else
            {//show a message indicating that printing was cancelled
                JOptionPane.showMessageDialog(new JFrame(), "User cancelled printing session", "Error 25: Cancelled",JOptionPane.ERROR_MESSAGE);
            }
        }
        catch (PrinterException pe)
        {// Printing failed, report to the user
            JOptionPane.showMessageDialog(new JFrame(), "Printing failed...WHAT DID YOU DO??", "Error 26: Failed",JOptionPane.ERROR_MESSAGE);
        }



    }

On my computer this program prints 3 pages. I'm on WinXP SP3.

import javax.swing.*;

public class PrintProblem { 

    public static void main(String[] args) {
        JTextArea txtA = new JTextArea();  
        // fill up
        for(int i=0; i < 100; i++)
          txtA.append("this line forever " + i + "\n");

        try         {
            boolean complete = txtA.print();
 
            if (complete)
            {//show a success message
                JOptionPane.showMessageDialog(new JFrame(), "Printing Page\n" + "Please click finish after printing", "Finished",JOptionPane.INFORMATION_MESSAGE);
//                btnFinish.setEnabled(true);
            }
            else
            {//show a message indicating that printing was cancelled
                JOptionPane.showMessageDialog(new JFrame(), "User cancelled printing session", "Error 25: Cancelled",JOptionPane.ERROR_MESSAGE);
            }
        }
        catch (Exception pe)
        {// Printing failed, report to the user
            JOptionPane.showMessageDialog(new JFrame(), "Printing failed...WHAT DID YOU DO??", "Error 26: Failed",JOptionPane.ERROR_MESSAGE);
        }
  } 
 
}

The attached zip has a .ps file with what was printed.

sigh

thnx for the help, but it looks like theres no easy way to solve this, I've gone through a few forums, but none of them works. It looks like i'm not the only one with this problem, I've solved the problem for now by using 3 jtextareas, atleast I know it will print the first page of each one.

krefie

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.