Help printing jtextpane?

Hi, Please help me... Im trying to do a little desktop application but im a little lost in two topics.
1) I want to change the font. Im using javax.swing.text.styles i found how to change color, to change size or to bold it. But i dont know how to change the font style.
2) I found this code to print, and it works, but i want to change the printer settings and save them for further use.
public int print(Graphics g, PageFormat pf, int page) throws PrinterException{
          if (page > 0) { /* We have only one page, and 'page' is zero-based */
               return Printable.NO_SUCH_PAGE;
          /* User (0,0) is typically outside the imageable area, so we must
           * translate by the X and Y values in the PageFormat to avoid clipping
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pf.getImageableX(), pf.getImageableY());
          /* Now print the window and its visible contents */
          jTextPane1.printAll(g);
          /* tell the caller that this page is part of the printed document */
          return Printable.PAGE_EXISTS;
     }PD im usign net-beans and im almost new

Here is an easy solution for you to print JTextPane content.
Use the freely downloadable "Smart JPrint" classes from http://www.activetree.com that allows you to automatically print and preview the content by breaking the content into multiple pages (icons and text both). The "AtDocumentPrinter" class has the print() and preview() method that takes a JEditorPane as the argument and rest is done for you with page setup, printer discovery, printing preview in a UI, and then print to a printer.
I think this will very much solve your printing problem without any wastage of time.

Similar Messages

  • Need helping printing to networked printers.

    I need help setting up network printers that have a code on them for each individual. There is no place to put a code so the printer will know who is printing what. I have installed 3 printers and they will not print, they just go to a paused mode and when you hit resume in reverts back to pause because it is looking for a code. I have tried it another way but it asks for a user name and password and all we have are codes. The workplace is using a windows based server and the copiers are listed as followed.
    Konica biz hub c450
    Sharp ar m700n
    sharp mx700n
    I need help to be able to print from my mac. I also have parallels running with xp installed and all the printers are installed on that side and printing fine. Hopefully someone can help me out.
    Thanks in advance

    Hello and welcome to Apple Discussions.
    In order to provide the user with the ability to input a user code, the respective printer driver would have to provide the facility. If this feature did exist on a previous version of OS X, then you may have to check the vendors web site to see if there is a driver for 10.6.
    If you are not sure if the function was supported previously, then go through all the user menus for the driver. The function may be present but located in an unusual location. Or it could require an additional file (aka plugin) that could be missing from the driver installation or not compatible with 10.6.
    The other thing to note is that if you have the Mac's printing via a Windows queue, you will have to provide user credentials for SMB print queues. This is typically a Windows user account - not the Mac's account details. If you don't want to create accounts for the Mac users on the Windows server, then you can use LPD rather than SMB to connect to the Windows queues. This does require UNIX Printing Services to be enabled on the server.
    Pahu

  • How to print JTextPane containing JTextFields, JLabels and JButtons?

    Hi!
    I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
    I wrote this small programm to demonstrate my problem:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.print.PrinterException;
    public class TextPaneTest2 extends JFrame {
         private void insertStringInTextPane(String text,
                   StyledDocument doc) {
              try {
                   doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
              catch (BadLocationException x) {
                   x.printStackTrace();
         private void insertTextFieldInTextPane(String text,
                   JTextPane tp) {
              JTextField tf = new JTextField(text);
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(tf);
         private void insertButtonInTextPane(String text,
                   JTextPane tp) {
              JButton button = new JButton(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(button);
         private void insertLabelInTextPane(String text,
                   JTextPane tp) {
              JLabel label = new JLabel(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(label);
         public TextPaneTest2() {
              StyledDocument doc = new DefaultStyledDocument();
              StyledDocument printDoc = new DefaultStyledDocument();
              JTextPane tp = new JTextPane(doc);
              JTextPane printTp = new JTextPane(printDoc);
              this.insertStringInTextPane("Text ", doc);
              this.insertStringInTextPane("Text ", printDoc);
              this.insertTextFieldInTextPane("Field", tp);
              this.insertTextFieldInTextPane("Field", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertButtonInTextPane("Button", tp);
              this.insertButtonInTextPane("Button", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertLabelInTextPane("Label", tp);
              this.insertLabelInTextPane("Label", printTp);
              this.insertStringInTextPane(" Text Text", doc);
              this.insertStringInTextPane(" Text Text", printDoc);
              tp.setEditable(false);
              printTp.setEditable(false);
              this.getContentPane().add(tp);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible(true);
              JOptionPane.showMessageDialog(tp, "Start printing");
              try {
                   tp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
              try {
                   printTp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new TextPaneTest2();
    }First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
    Thanks!

    I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.

  • I need help printing with HP laserjet 2200 and OS 10.6

    I need help setting up my HP laserjet 2200 and OS 10.6 -- I've downloaded and installed all the software and still can't print.

    Hey jeo1951,
    If you haven't already, try running through the recommended steps in the following article:
    Mac 101: Printing (Mac OS X v10.6)
    http://support.apple.com/kb/HT3771
    It should help you set up your printer.
    Welcome to Apple Support Communities!
    All the best,
    Delgadoh

  • HELP- Printing Problem with Photoshop CS4

    Hello Everyone,
    I just bought the PHOTOSHOP CS4, and I am having problem when it prints. The image is not clear, it has dots (pixels). This computer where I installed this program is brand new. I have previously worked with Photoshop CS2 and never had an issue but was force to buy this new one because the computer that I bought has Windows Vista and CS2 is not compatible. I thought maybe the problem was my printer but is not I have a Brother HL-5140 (black and white). I have connected my old computer with the printer and the images print perfectly fine. I have printed photos and it prints clear. But this only happens with Photoshop CS4. It prints dots, can someone please help me. Is driving me crazy.

    Really I'd be willing to bet it's your driver under Vista.
    I have the same problem using Vista and a older HP LaserJet, under XP and CS2 it prints well. Under Vista it's a bunch of dithered pixelated dots.
    They want you to buy a newer printer.

  • HELP printer compatability with computor.

    Help...Have hp psc 1310  hp officejet 4200 series......Got a new gateway which is Vista and my old one was XP......my printer will print, but can not scan and tried to program the cd in again and computor would not accept it.  Will I need to get a new printer that is compatable with Vista?   Any thing to update of just have to get new?
    thanks enhelder
    Message Edited by enhelder on 07-07-2009 10:51 AM

    Hello Highcountryhike,
              Thank you for posting your request.  You should have no issues updating to 10.10 Yosemite.  Below are a couple links that should help.
    If you run the Software Updates from the Apple Menu, to check for updates.  Some have had issues not seeing updates, so simply click on "Store" from the top menu, and then click on Reload Page".  Select to install HP Updates to ensure you have the latest drivers.
    In some instances, the printer can be updated in the printer queue to resolve other issues, so check to make sure that the printer is listed with the HP Printer Series driver and not just AirPrint.  System Prefernces/Printers & Scanners/ select your printer on the left and check on the right side under "Location:" that Kind: is the printer series.  You can also click the "-" symbol to remove and then re-add the printer queue again, choosing the HP Printer series name to install the drivers.
    Installing the Full Feature HP Printer Driver in OS X v10.10 Yosemite
    Mac OS 10.10 Yosemite and HP Printer Support
    Please post back with any further issues/questions.
    Thanks,
    Double-U-Dee
    Don't forget to give Kudos where Kudos is Due - OR - if a Response Resolved your Issue, Click the "Accept as Solution"
    I am an HP employee, but my posts and replies are my own and do not reflect the opinion of HP.

  • Help printing raw profiling target!!

    I know this has been beaten around, but I am looking for help, and the latest information on printing a raw target for printer profiling. I'm having troubles getting a decent target to profile.
    First PSCS4, OSX 10.6.8 (Snow Leopard), Mac Pro Tower, Epson 1400 inkjet printer with Epson Claria inks. Driver is the Epson SP 1400 Series driver. Nozzle check and print head alignment are fine.
    I printed out an untagged RGB test strip file four times on the same sheet of glossy paper. This file has 21 steps of gray, four each of red, green and blue, and three each of cyan, magenta and yellow. I use this file to help me pick the best driver settings when creating RGB printer profiles.In each case, the Epson driver used the exact same settings, with Color Management set to No Color Adjustment. Here are the PS dialog settings I used in each test print:
    1. Untagged file, No Color Management in print dialog box
    2. Untagged file, Printer Manages Color, RelCol, no BPC (according to Eric Chan, rendering intent is ignored in this mode)
    3. File tagged with ARGB, Photoshop Manages Colors, profile set to ARGB destination profile, RelCol, BPC turned off.
    4. File tagged with sRGB, Photoshop Manages Colors, profile set to sRGB destination profile, RelCol, BPC turned off.
    I've been wary of Photoshop's "No Color Management" for awhile in Snow Leopard due to reported OS override, etc, but I wanted to compare the above four methods. Items 3 & 4 above were reported as workarounds on the Luminous Landscape site.
    I found that methods 1 and 2 (NCM and Printer Manages) were very close to each other, within spectro error and usually less than 0.5 Delta E. Item 3 (ARGB to ARGB) should be identical, since it is a null conversion, but it is very different from 1 and 2. Item 4 (sRGB to sRGB) was different from the ARGB to ARGB conversion and also different from 1 & 2 by the widest margin. Holy smokes, folks! So, at least with the PSCS4, OSX 10.6.8 and the Epson 1400, the Luminous Landscape workaround does NOT work. While 1 and 2 seem to be a pretty good match, I have no idea whether they are both accurate RAW output, or whether they are both the same and both similarly flawed.
    I just want to build a damn profile. I've been studying and using color management for 15 years, so I am not exactly new to this stuff.
    HELP!!!
    Thanks,
    Lou Dina

    Thanks, Dave.
    That worked. I just created a glossy profile and got a great print from my new profile.
    Best, Lou

  • Need help - Print Menue in Acrobat Pro and Standard

    Hello,
    at first, i have to apologize for my bad englisch because I'm german.
    I downloaded a Trial of Acrobat pro and there I hava an extended Print menue where I can choose individual Color Profiles.
    There is an image attached.
    But I don't really need the Acobat pro Features, because I need Acrobat only for Color Printing on my Printer. And it ist expensive.
    So my Question to you is: Is this extended Print menue also in Acobat 9 Standard?
    There is no Trial, so that I hope, that someone can help me.
    Can I also set this settings in Acrobat 9 Standard?
    Thank you very much for helping me with my buying decision.
    Greetings from Munich
    Sebastian

    The Advanced Print menu in 9 Standard does not have all of the options that are in your screen shot.
    Checked with a coworker who has 9 Standard, and the options are much more limited. (I have 8 Pro).
    Bad news is you would need 9 Pro.
    Saw this the other day; sorry for the slow answer, good luck.

  • Need help printing in Classic to HP 1510

    I'm helping a person with an early 2001 iMac (500 MHz, 384 MB RAM) who's running 10.2.8 and 9.2.2. She got an HP 1510 all-in-one printer/scanner, and I'm trying to get it set up. I installed the printer software for OS X and for 9.2.2 (while running under 9.2.2) I can print from a 9.2.2 application (like Word for Office 2001) while running under 9.2.2, and I can print from an OS X application, but I can't print from a Classic application under OS X!
    When she tries to print from Office 2001 under Classic, the HP 1510 printer is found under "Page Setup" and "Print" in the Office 2001 application, the print job spools, but the Print Manager under Classic claims no printer is installed, and the Chooser under Classic can't find a USB-based printer under "HP Inkjet v6.6.1". This is where I found the USB-based printer when she was running 9.2.2. She has tried running the Desktop Printer Setup utility under Classic, but it doesn't see the USB-based HP 1510.
    What do I need to do to enable printing under Classic?

    gave up.

  • HELP - Print to Video

    I so frustrated. I'm trying to print to Video to Archive my old footage. Final Cut reconizes my camera that I'm Printing to but when I go to print all I get is blue screen. I Printed to Video before and it worked fine. I'm connecting with Firewire. It's on the VCR setting. Am I missing something.
    Please help
    PowerMac G5   Mac OS X (10.4.2)  

    As I recall, Canon's need some funny business with record-pause in VCR mode. I used to have to do this sequence with my GL2 and I think that while the XL2 is a far better instrument, the software for this is probably related. I always had to use the remote to make it work easily with the GL2. Search your manual for instructions around this record pause thing and I think you may find the solution.

  • PDF help. printing PDFs make acrobat or reader go not responding.

    Whenever i try to print or go to print setup in either Acrobat or Reader it cause the program to not respond and i will have to exit the program and it will not print. But if i right-click a .pdf file (like saved on my desktop) and click print it will print just fine.... I am using Acrobat 8.2.6....i think. Any help would be greatly appreciated, thanks.

    As Michael said, it is probably a conflict between the two. You may be able to uninstall Reader (assume you have Reader 9) and repair Acrobat. Uninstalling one will usually break the other and the repair should fix it.

  • HELP - Print PDF to iPhoto Workflow Failure

    Hi folks - I am trying to export to iPhoto from Pages by following these steps...
    File > Print > PDF > Save PDF to iPhoto
    iPhoto then launches and I'm asked to select an album. No matter what option I select at this point, once I hit "Continue" I receive a "Workflow Failed" error in the upper right of my screen.
    Anyone have a fix or work-around for getting Pages documents into iPhoto?
    Thanks!
    Tom

    Hello Tom,
    welcome to the Pages Discussions. I can't help you to solve your problem, but for other members, it would be helpful, when you post a few details about your software versions (Pages, iPhoto, Mac OS X) and about your hardware. As more infos you post as quicker the answers can arrive without reposts of questions.
    Frank.

  • Someone Help Print To Go

    Hi All,
    I just can't get connected - when I download PTG software right at end Printers box message 'Operation could not be completed' but then says PTG installed successfully.
    When I go to print a document PTG shows and  after selecting it I go to pairing mode all = ok thena box titled  Print To Go Connecter box says PTG has encountered a problem and needs to close. ?
    Please someone help !I have turned AVG firewall off etc but still can't get it to work !!
    Many thanks
    Doug

    Is your computers using Win7? I use XP PRO and it works fine. A few people using Win7 are having problems.

  • Please help printer wont print a legal document

    please help me printer wont print legal documents??? 

    Hi,
    which printer do you have is it an Officejet, laserjet or a Photosmart?
    I work for HP but my posts and replies are my own.
    Make it easier for other people to find solutions, by marking my answer with \'Accept as Solution\' if it solves your problem.
    Click on the BLUE KUDOS button on the left to say "Thanks"

  • Help printing information

    hi
    i have a class "Club"
    it contains an ArrayList, add and remove methods and a method to retrieve player details. (The code for class Club is provided below).
    i want to write a new class called Main which prints out the information held about each player in the club.
    is this possible and if so how would i go about achieving this?
    Any help would be greatly appreciated.
    Many thanks.
    public class Club
        public String clubname;
        ArrayList<Player> players = new ArrayList<Player>();
        public Club(String clubname)
           this.clubname = clubname;      
        public void addPlayer(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed)
            players.add(new Player (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed));
        public void removePlayer(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed)
            players.remove(new Player (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed));
        public void addBowler(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed, int ballsbowled, int wicketstaken, int runsconceded)
            players.add(new Bowler (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed, ballsbowled, wicketstaken, runsconceded));
        public void removeBowler(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed, int ballsbowled, int wicketstaken, int runsconceded)
            players.remove(new Bowler (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed, ballsbowled, wicketstaken, runsconceded));
        public void addWicketKeeper(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed, int catches, int stumpings)
            players.add(new WicketKeeper (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed, catches, stumpings));
        public void removeWicketKeeper(String firstname, String surname, int age, double height, int weight, int gamesplayed, int runsscored, int timesdismissed, int catches, int stumpings)
            players.remove(new WicketKeeper (firstname, surname, age, height, weight, gamesplayed, runsscored, timesdismissed, catches, stumpings));
        public Player retrievePlayer(String firstname, String surname)
            Player retPlayer = null;
            for (Player player : players)
                if (player.getFirstname().equals(firstname) ||
                  player.getSurname().equals(surname))
                    retPlayer = player;
            return retPlayer;
        public String getClubname()
            return clubname;
    }

    hi,
    iv written the following code in my main class
    however, i want to write a getDetails method in the player class
    i dont know where to start with this
    i would appreciate any help on the matter
    thanks very much
    public class Main
         public void playerDetails(Club theClub)
              List<Player> playerList = theClub.players;       
              for(Player p : playerList)       
                      System.out.println(p.getDetails());       
    }

Maybe you are looking for