Results 1 to 6 of 6
  1. #1
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Printing in a printer

    Hello guys,
    I need the source code to print from a Jtable or JTextArea using a printer. I have no class of this job.Now I am unable to make that.
    Anyone ,please help me.



    Thanks in advance.


    Ujjal
    Dhaka
    Bangladesh

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    Hello guys,
    I need the source code to print from a Jtable or JTextArea using a printer. I have no class of this job.Now I am unable to make that.
    Anyone ,please help me.



    Thanks in advance.


    Ujjal
    Dhaka
    Bangladesh

    there is no source code i can post here but you can use the print() method in the JTable or JTextArea class to print its content.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Java Code:
    there is no source code i can post here but you can use the print() method in the JTable or JTextArea class to print its content.


    Can you give me an sample example of print() method which will print a document or a String from JTextField or JTable using printer?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    Java Code:
    there is no source code i can post here but you can use the print() method in the JTable or JTextArea class to print its content.
    Can you give me an sample example of print() method which will print a document or a String from JTextField or JTable using printer?
    Have you read the API documentation for those two classes? If so, you'd seen that a simple method call print() is all that is needed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    when i execute the following code my print driver is called twice (first for printing a jtable and then for printing the textarea) where i can change the printer and/or different print properties. when you call print() on these classes the statement must be surrounded by a try/catch-block, because the method throw a PrinterException. furthermore print() accept different arguments, for more informations look here JTable (Java Platform SE 6)


    Java Code:
    import java.awt.print.PrinterException;
    
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    
    
    public class PrintfExamples {
    
    	public static void main(String[] args) {
    		JTable table = new JTable();
    		JTextArea textarea = new JTextArea();
    		
    		try {
    			table.print();
    			textarea.print();
    		} catch (PrinterException e) {
    			e.printStackTrace();
    		}
    	}
    }

  6. #6
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    j2me64,
    Thanks for the example.It is quite easy and it's working.Actually I have no printer connected in my PC.Will it work?
    I think ,it will work.



    JosAH,
    Thanks for your link.

Similar Threads

  1. printing to printer
    By ak88 in forum Advanced Java
    Replies: 3
    Last Post: 01-13-2013, 03:32 PM
  2. Printing Text using printer
    By UJJAL DHAR in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 04:26 PM
  3. Replies: 4
    Last Post: 09-10-2009, 01:40 PM
  4. Replies: 2
    Last Post: 02-20-2009, 07:25 AM
  5. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 01:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •