Results 1 to 7 of 7
  1. #1
    Jared is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Printing from JList

    Hi
    I have a simple program to capture data into a JList. I am now having a problem to print- how do you print the contents of a JList.

    I have seen the code for printing contents from a Jtable and tried playing around with it to suit JList but no luck.
    Am using Netbeans 7.
    Any ideas?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default Re: Printing from JList

    What code have you tried? What didn't work about it?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,786
    Rep Power
    5

    Default Re: Printing from JList

    Have you read the Javadoc for JList? For any new class you are using you should read the documentation for all the methods before you use it. There should be some hints there.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Jared is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Re: Printing from JList

    Hi
    IDE using: Netbeans import java.text.*; import java.awt.print.*; Code is behind a button. ================================================== ================================== Following code works for Jtable: private void cmd_printActionPerformed(java.awt.event.ActionEven t evt) { ***************************************** ******MessageFormat header = new MessageFormat("Report"); ********MessageFormat footer = new MessageFormat("Page{0,number,integer}"); ****try ****{ ********Mytablename.print(JTable.PrintMode.NORMAL, header, footer); ****} *******catch (java.awt.print.PrinterException e) *****{ ********System.err.format("Cannot print",e.getMessage()); ****} *** ****} ** ================================================== ================================= Following changes I made: private void cmd_printActionPerformed(java.awt.event.ActionEven t evt) { ***************************************** ******MessageFormat header = new MessageFormat("Report"); ********MessageFormat footer = new MessageFormat("Page{0,number,integer}"); ****try ****{ ********Mylistname.print(JList.PrintMode.NORMAL, header, footer); ****} *******catch (java.awt.print.PrinterException e) *****{ ********System.err.format("Cannot print",e.getMessage()); ****} *** ****} ** ================================================== ================================= NB: PrintMode does not seem to work with List

  5. #5
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Printing from JList

    Please use code tags when posting.

    Though I will give you a hint. JList has a function that returns as a ListModel<String>, this can be used to find each string in the JList, given the index.
    Last edited by zFollette; 12-31-2013 at 09:52 PM.

  6. #6
    Jared is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Re: Printing from JList

    Will that mean running a for loop or maybe a counter to print everything in the JList.
    Thanks for the hint.
    Last edited by Jared; 01-01-2014 at 01:25 AM.

  7. #7
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Printing from JList

    Yes, you will have to use a for loop

Similar Threads

  1. Replies: 4
    Last Post: 01-10-2012, 02:05 PM
  2. Replies: 0
    Last Post: 12-26-2011, 04:52 PM
  3. Link one JList to another JList
    By mib1bee in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 08:10 PM
  4. Link one JList to another JList
    By mib1bee in forum Advanced Java
    Replies: 1
    Last Post: 12-30-2010, 07:35 PM
  5. Link one JList to another JList
    By mib1bee in forum New To Java
    Replies: 1
    Last Post: 12-30-2010, 07:24 PM

Posting Permissions

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