How to print a JTable  in Java Swing ?

Hi,
I have an application written in java swing.Now I want to write a print module that prints some details.The details includes the JTextArea and JTable that changes in size dynamically.One solution i found is to put them in a panel and print that panel.But it is static.The size of JTable and JTextArea changes, according to the given input.Please give me a solution for this.

Printing is a bit of a nightmare, actually. Most of the trouble is layout. Basically a Printable is passed a page number and a graphics context and has to work out what components go on that page and where. It can't depend on the pages being requested in sequence.
You can call getPrintable from a JTable, and you can call that through your own Printable in order to add extra pages. However you can't ask a Printable how many pages it's going to produce, you just have to invoke it and see if it returns a code to say that the page is out of range.
And the Printable JTable generates is very limited, the table has to occupy full pages, you can't tell it to start in a different place on the first page, or find out how much space it's used on the last page. The headers and footers generate JTable's own idea of a page number, not yours.
You can call print() on most Swing components, but you'll need to set their size and location first, and/or mess with the transformation in the graphics context.

Similar Messages

  • How to store the datas in a .txt file in to a JTable in Java Swing

    Hi sir,
    Here i want to know how to store the data's of a .txt file
    in to a JTable in java swing.
    Where here the .txt file like for eg,spooler.txt is in the server and from there it will come to my client machine what i have to do is to take that .txt file and store the datas of the .txt file
    in a JTable.This is what i want.So pls. do help and provide the code as well.I will be thankful.Since i am involved in a project which involves this it is Urgent.
    Thanx,
    m.ananthu

    You can't just display data from a text file in a JTable. You have you understand the structure of the data so that you can parse the data and create a table model that can access the data in a row/column format. Here is an example of a simple program that does this:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172

  • How to print a text in java?

    How to print a text in java?

    of corse, i have JTextField in my frame that i want to extract the text and print it on a paper with a printer.

  • How to do a dropdownlist in java Swing much like a JMenuBar items

    Hi sir,
    Here i want to know how to do a dropdownlist in java swing much like a JMenuBar items falling from the top to bottom .Here i should not use JMenuBar in any way.
    So that i need to do the dropdownlist by using other feature only.Since i am new to this.I need ur help urgently.Pls do provide the code for this so that i will be so gratefull to u.It is very Urgent.Since i have involved in a project which involves this feature.Pls. do provide the answer as well as the code quickly as possible.
    Thanx
    m.ananthu

    use JComboBox
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

  • How To Call HTML Page Through Java Swing Page  ???....

    Hi All ;
    Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
    Regards ;

    Hi,
    you can use HTML fragments on a panel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    However, to integrate a browser you need 3rd party software like IceBrowser
    If you Google for: HTML Swing
    then you find many more hints
    Frank

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • How to connect autocad file to java swing

    hi,
    plz immediately tell me how to connect autocad file to java swing .
    plz help me
    it is very urgent

    Hi there
    See if the link below helps you out.
    Click here to view
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • How to Print entire Jtable

    hi
    I have used Jtable.print() command to print the JTAble but problem is that it is printing only that data which is visible row wise i.e.
    if in a row one column's data is shown like
    nam...
    then it is printing like that only
    i want to know how to print all data irrespective of how it is viewable on screen in table
    please help me out
    its urgent
    thanks

    package table;
    * PrintTableDemo.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class PrintTableDemo extends JFrame {
        private JButton btPrint;
        private JTable table;
        private JTable tableToPrint;
        public PrintTableDemo() {
            super("PrintTableDemo");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(190,150);
            setLocationRelativeTo(null);
            table = new JTable();
            btPrint = new JButton();
            table.setModel(new DefaultTableModel(
                new Object [][] {{"this should print entirely", null}},
                new String [] {"Title 1", "Title 2"}
                Class[] types = new Class [] {String.class, String.class};
                boolean[] canEdit = new boolean [] {false, false};
                public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
            getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
            btPrint.setText("Print...");
            btPrint.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent evt) {
                    btPrintActionPerformed(evt);
            getContentPane().add(btPrint, BorderLayout.NORTH);
        private void btPrintActionPerformed(final ActionEvent evt) {
            tableToPrint = new JTable(table.getModel());
            tableToPrint.setSize(500,1500);
            tableToPrint.getColumnModel().getColumn(0).setWidth(200);
            tableToPrint.getColumnModel().getColumn(1).setWidth(200);
            try {
                tableToPrint.print();
            } catch (PrinterException ex) {
                ex.printStackTrace();
        public static void main(final String args[]) {new PrintTableDemo().setVisible(true);}
    }

  • How to print the table in java.

    we want to take the print out of JTable in java.
    But we have some other components on the GUI
    alongwith the JTable.Now our query is that how cud
    we take the print out of JTable only?
    we are using jdk1.4.2 version of java.In this version
    we don't have any direct method of taking the print out
    of JTable.
    Any valuable suggestion will be appreciated.
    Thanks.

    You don't have to use a reporting tool:
    http://java.sun.com/docs/books/tutorial/2d/printing/in
    dex.html
    Okie! Thats only a suggestion. Im sorry.

  • How to print  Excel file in java?

    Hi, all
    I had written a program to generate a Report with Excel in java using the jexcelapi_2_5_7 . But I don't know how to print it in java program. It seems that java print Service don�t support Excel flavor. How should I do? It will be a great appreciate for me if anyone could help me.
    Regards
    David

    Hi ,
    i m asking if you got a solution for your problem ;
    i need solution to the same problem
    thx in advance

  • How to use a DropDownList in Java Swing.Its very very Urgent

    Hi Sir,
    Here i need to know how to do (or) create a dropdownlist by using Java Swing.I know that there is JMenuBar & JMenuItems without using that when i click a JButton for example the dropdownlist should come from the top to bottom.I have already posted this quesion once.And i found that it has been removed.So i hope that this time i will get a better answer.Pls.do provide the code as well sir.So that i will be very thankful to u.Since i am involved in a project which contains this
    feature.It is very very Urgent.So pls.do provide the code i will be waiting for the reply.
    Thanx,
    m.ananthu

    use JComboBox
    JComboBox liste = new JComboBox(new Object[]{"azerty","qwerty});the api documentation :
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html
    the turotial on combobox :
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

  • How to print a Pdf from Java script

    Hi,
    I need to print a pdf from java script. In java script i have url of pdf. Is there any way to print pdf from java script?
    I am able to print word doc by ActiveX. is there any activeX or something else which do the same thing for pdf?
    Any help heartily esteemed to me.
    Thanks
    Kamlesh Sharma

    you are cross postin .. your thread has been answered in the jsp jstl forums

  • How to play flash files in java swings

    Hi All ,
    I have a requirement in java swings , i want to play advertisements ( flash files in swings )
    can any one provide any example for the above requirement .
    Thank you all for sharing knowledge in this great forum .
    Jerry

    I have a java desktop application which is actually a
    kiosk application. I have to run some promotion
    videos in my application when no user is using the
    kiosk.Will the kiosks all be running the same OS?
    The reason I ask is that JMF is available in both
    standard and performance pack versions. The PP
    provides a wider variety of formats, but runs only
    on Win. and *nix.
    videos can be any avi or neother which can easily be
    played in java applications.That is handy. The JMF standard pack provides
    support for a number of flavors of AVI, but not all.
    What is the best way for me to play video files in a
    java application??I would suggest checking if the 'standard' version
    of the JMF can play* the current AVI's. If it can, use
    the standard JMF for the project, if not, look to
    converting the AVI's to something the JMF can
    deal with, this might involve storing the video or
    audio of the AVI's in a different format - you
    might have to experiment to get the right
    combination, but the JMF 'supported formats'
    is a good guide.
    http://java.sun.com/products/java-media/jmf/2.1.1/formats.html
    * To check if JMF can play them, install it and
    try loading the AVI's in JMStudio - the default
    player.

  • How to fix the value of first column in the JTable in java swing for every

    Hi ,
    I have a swing page that have table panel in which there is a table of size 7x4 now when I click on the perticulat row then that row data will displayin the table like that the selected row become the second column in the new table and the fist column of this table will remain constant for all the entry but the second column update according to the roe which is selected .How it is possible .
    Thanks in Advace,
    anu

    One thing you can do is to prevent the user from editing that column and programatically supply the values of that column yourself.
    JTable table = new JTable() {
       public boolean isCellEditable(int row, int col) {
           if(col == 0) {
              return false;
           return super.isCellEditable(row, col);
    };This allows you to prevent the user from editing the column information so you can supply some sort of a default value for the column always
    ICE

  • How to print a PDF file from Swing(JFC/swing)

    Hi,
    I am able to dislay a PDF file in Swing but how can I print it from there. I want to do it without using Acrobat reader.

    You can use the "System Exec.vi". The command line should have the following structure:
    "<Path to AcroRd32.exe>" /t "<Path to document>" "Printer name"
    For example"
    "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /t "C:\myreport.pdf" "Tektronix Phaser 300i"
    Regards;
    Enrique
    www.vartortech.com

Maybe you are looking for

  • HT201178 how do you unpair an apple wireless keyboard?

    I have an apple wireless keyboard, but I recently just purchased and apple keyboard with numeric keypad and I am wondering if I need to unpair the apple wireless keyboard from bluetooth or I dont know but, my new keyboard is wired so it should work a

  • Why did my external monitor stop working

    I bought a brand new iMac on Saturday. Came home. Migrated from my MBAir (mid-2011). Plugged in my Samsung 27' TV (via Moshi HDMI to Thunderbolt converter) and it worked just great. Beautiful picture on both iMac 27 AND Samsung...Until this morning.

  • Is there a way to keep Siri from giving home address?

    I discovered that Siri will give my home address when the home button is pressed when locked. How can you keep that from happening if it's lost or stolen?

  • EL fails in my JSP-files

    Hello, today i installed JSTL 1.1 using Tomcat 5.0.25 and J2SDK1.4.2_03. I noticed, that the EL-expressions are only evaluated, if the jsp-files are located in the root-directory of my web-application. My usual location for jsp-files is /WEB-INF/jsp

  • My new MacBook pro is not turning on!please give me solution!!

    My new 2012 MacBook pro is not turning on!i already set up the mac!next day when I tried to start it,it was not turning on!i tried with pressing command,control and power button together but it's not working!!please help!!