Text printing in JtextArea component

I have created a swing application In which i have used Jtextarea component to print output using thread. To write output i m using append method. When thread print the output in text area it is appended but to see these output I need always to sroll the page,
Is there any way that when output is printed it should be appeared on screen at lower portion of text editor.

I have use the following code but it is very slow
logTextArea.append("your text");
logTextArea.setCaretPosition( logTextArea.getDocument().getLength() );

Similar Messages

  • How can I assign a text file to JTextArea component??

    Hi every body, does any boody has a code for read a text file and show this text in a JTextArea??? I'm trying with a FileReader but the text doesn't appear well.
    Thanks in advance.
    Juan

    String s = "";
    BufferedReader reader =
                             new BufferedReader(new FileReader(path));
                        String temp = reader.readLine();
                        s += temp + "\n";
                        while (temp != null)
                             temp = reader.readLine();
                             if (temp != null)
                                  s += temp + "\n";
                        reader.close();
    textArea.setText(s);

  • CR duplication when Copy/Pasting text from a JTextArea

    I have a typical scenario of having text in a JTextArea. When I select some of that text and try to paste it either to an external text editor or even in the same JTextArea, I am getting extra line spaces in the screen.
    For example, if I have the following text:
    <a id=1>
       <b/>
    </a>When I copy paste it, I get:
    <a id=1>
       <b/>
    </a>When I looked to see what characters were being used for the CR, I see "\r\n". This is the standard line.seperator for Windows OS which is fine. When I save this text to a file using the Java I/O libraries, it is fine (no extra lines). But when copy/pasting it prints extra lines.
    Has anyone had similar problems?

    Has anyone had similar problems? No. How are you doing the copy/paste? Did you write your own routines or are you using the default Actions. By default, when a Document is loaded it will convert the "\r\n" end of line string to "\n" and store the single character in the Document. When you use the getText(..) method the enod of line string will be expanded to "\r\n" on a Windows system, but this should not happen in a copy/paste operation. How do you add data to your text area?
    This section from the Swing tutorial on "Text Component Features" has a working example of using copy/paste:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

  • Very strange spacing when printing a JTextArea

    I am trying to print text from a JTextArea and am having a very hard time at it. I am using a print utility which takes the component itself to be printed.
    For instance:
    If my JTextArea contains the text:
    "Item: Large Caffe Mocha"
    The printer will spit out something like:
    "Item: Lar ge Caf f e Mocha"
    Does anyone have any idea what is happening here?
    Code is as follows:
    public class PrintUtilities implements Printable {
      private Component componentToBePrinted;
      private boolean interactive;
      public static void printComponent(Component c, boolean interactive) {
        new PrintUtilities(c, interactive).print();
      public PrintUtilities(Component componentToBePrinted, boolean dialog) {
        this.componentToBePrinted = componentToBePrinted;
        interactive = dialog;
      public void print() {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog())
          try {
            System.out.println("Calling PrintJob.print()");
            printJob.print();
            System.out.println("End PrintJob.print()");
          catch (PrinterException pe) {
            System.out.println("Error printing: " + pe);
      public int print(Graphics g, PageFormat pf, int pageIndex) {
        int response = NO_SUCH_PAGE;
        Graphics2D g2 = (Graphics2D) g;
        Dimension d = componentToBePrinted.getSize(); //get size of document
        double panelWidth = d.width; //width in pixels
        double panelHeight = d.height; //height in pixels
        double pageHeight = pf.getImageableHeight(); //height of printer page
        double pageWidth = pf.getImageableWidth(); //width of printer page
        double scale = pageWidth / panelWidth;
        int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
        //  make sure not print empty pages
        if (pageIndex >= totalNumPages) {
          response = NO_SUCH_PAGE;
        else {
          //  shift Graphic to line up with beginning of print-imageable region
          g2.translate(pf.getImageableX(), pf.getImageableY());
          //  shift Graphic to line up with beginning of next page to print
          g2.translate(0f, -pageIndex * pageHeight);
          //  scale the page so the width fits...
          g2.scale(scale, scale);
          componentToBePrinted.paint(g2); //repaint the page for printing
          response = Printable.PAGE_EXISTS;
        return response;
    }I am calling it as follows:
    JTextArea area = new JTextArea("Large Caffe Mocha");
    area.setRows(20);
    area.setColumns(75);
    area.setLineWrap(true);
    JScrollPane pane = new JScrollPane(area);
    printReceipt(area);
    public void printReceipt(Component componentToBePrinted)
            PrintUtilities.printComponent(componentToBePrinted); 
    }Thanks for any assistance with this problem. It is elluding me..

    public static void printComponent(Component c, boolean interactive) {
    new PrintUtilities(c, interactive).print();
    printReceipt(area);
    public void printReceipt(Component componentToBePrinted)
    PrintUtilities.printComponent(componentToBePrinted); 
    }I'm sure that this is not causing the issue and am also surprised that the compiler didn't complain, but your call to PrintUtilites.printComponent() doesn't sync up with the function you are calling. You are sending only one parameter (componentToBePrinted) and the printComponent() function is expecting two parameters: the component to be printed and a boolean value. In the code that you posted, you only had the one printComponent() function listed, with no alternative function that only accepts the component to be printed.
    Having pointed this out, I'm not sure as to what is causing the issue, except that it may have something to do with your code:
    //  scale the page so the width fits...
    g2.scale(scale, scale);Maybe it's not really a spacing issue so much as a scaling issue. I know that on some systems, when you scale the graphics to print that are simple text, some letters will come out further apart and some will be squeezed together. I would suggest that you try commenting out your scaling code and let it print at the scale that it wants, just to see what happens.
    Cheers,
    Sean Carrick
    PekinSOFT Systems
    Edited by: PekinSOFT.Systems on Apr 16, 2009 8:27 PM

  • How can i turn a part of a text of  a JTextArea into bold??

    how can i turn a part of a text of a JTextArea into bold?? I mean i just want the selected text to do so and not all of the content of the JTextArea.
    Is there a way to do so??
    If not, is there another component that i can use to do so??
    [Rik]

    Use a JTextPane. Here's an example to get you started:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=342068

  • GUI. puting JScrollPanel in JTextArea component

    Hi. how can I pus JScrollPanel in JTextArea component rigt. that JScrollPanel would be wisable and usable???
    JTextArea is in JPanel(Layout = null), Jvanes is in Container
            Container con = getContentPane();
            pagr = new JPanel();
            con.add(pagr);JTextArea has to be in pagr.
    maybe someone has any suggestions?
            try {                      
                jbInit();             
            } catch (Exception ex) { 
                ex.printStackTrace();
        private void jbInit() throws Exception {
            pagr.setLayout(null);
            txt.setBounds(new Rectangle(10, 10, 475, 440));
            filtr.setBackground(UIManager.getColor("Button.disabledForeground"));
            filtr.setBounds(new Rectangle(490, 375, 185, 75));
            pasir.setBackground(new Color(230, 230, 230));
            pasir.setSelectionBackground(Color.blue);
            pasir.setSelectionForeground(Color.orange);
            pasir.setBounds(new Rectangle(490, 10, 185, 355));
            txt.setBackground(new Color(230, 230, 230));
            txt.setSelectedTextColor(Color.red);
            txt.setSelectionColor(Color.lightGray);
            pagr.setBackground(Color.lightGray);
            scrl = new JScrollPane(txt);
            scrl.setEnabled(true);
            scrl.setVisible(true);
            pagr.add(txt);
            pagr.add(filtr);
            pagr.add(pasir);
        }txt i JTextArea component.
    not working, also Designer Mesages box throws:
    Failed to create live value from JScrollPane scrl = null;: null
    Failed to create live visual subcomponent (scrl) as javax.swing.JScrollPane; creating a red component in its place

    I'm using null Layout that I would be able to pusall
    components where I want. prefering size umeanfiltr.setBounds(new Rectangle(490, 375, 185,
    75));
    and JScrollPane is subComponent of txt, atleast I want to to describe it that way.Did you miss my comment? You are adding text to the
    scrollpane but you are not adding the scroll pane
    anywhere. Also I would highly recommend that you use
    layout managers.
        JTextArea txt = new JTextArea(13,30);
        JScrollPane scrl = null;
        JList pasir = new JList();
        JButton filtr = new JButton("Filtruoti");
        JPanel pagr;
    //skiped some of code
        public Pradzia() {
            Container con = getContentPane();//              <--geting container
            pagr = new JPanel();
            con.add(pagr);//adding JPanel to con
    //skiped some of code
            try {                      
                jbInit();             
            } catch (Exception ex) { 
                ex.printStackTrace();
        private void jbInit() throws Exception {
            pagr.setLayout(null);
            txt.setBounds(new Rectangle(10, 10, 475, 440));
            filtr.setBackground(UIManager.getColor("Button.disabledForeground"));
            filtr.setBounds(new Rectangle(490, 375, 185, 75));
            pasir.setBackground(new Color(230, 230, 230));
            pasir.setSelectionBackground(Color.blue);
            pasir.setSelectionForeground(Color.orange);
            pasir.setBounds(new Rectangle(490, 10, 185, 355));
            txt.setBackground(new Color(230, 230, 230));
            txt.setSelectedTextColor(Color.red);
            txt.setSelectionColor(Color.lightGray);
            pagr.setBackground(Color.lightGray);
            scrl = new JScrollPane(txt);//                  <--ading JScrollPane to txt(JTextArea)
            scrl.setEnabled(true);
            scrl.setVisible(true);
            pagr.add(txt);//                              <--adding txt to pagr(JPanel)
            pagr.add(filtr);
            pagr.add(pasir);
    or I don't understand something.

  • Can't set selected text in a JTextArea (bizarre)!

    I've go this method here to select text in a JTextArea is doesn't work.
    Any ideas?? I haven't posted ALL the code because there is quite a lot of it in a number of classes.
    public void selection(int i)
              String meth = methods.get(i).toString();
              String tex = tc.getText();
              int pos = tex.indexOf(meth);
              if (pos != -1) {
                   myTextComponent.setSelectionStart(pos);                myTextComponent.setSelectionEndpos+meth.length));                
         }

    Selected text is only shown when the text component has focus. Assuming you are clicking on a button to invoke your code you would need to reset focus on the text field:
    myTextComponent.requestFocus();

  • How do I change the colour of text in a JTextArea?

    I was wondering if there is a method I could use to change certain parts of the text in a JTextArea to a different color, eg if you wished to highlight HTML tags in the source code, so they stand out from the rest of the text.
    cheerz

    Try this...
      // create text area
      JTextArea textArea = new JTextArea();
      // change text color to blue
      textArea.setForeground(Color.blue);
      // change background color to black
      textArea.setBackground(Color.black);

  • Getting the text from a JTextArea...

    hi, I'm making a perfect calculator program and I'm trying to add a Note Pad function to it, I also want to hide that so the other interface can be used; I can get it hided and come again but I'm wondering how could I get the text from the JTextArea INCLUSIVE the enters that are made withing it, so:
    theString = jTextArea1.getText();only gives me the text and no enters; suggestions?

    I think I displayed it wrongTwo things to keep in mind...
    Certain Swing components will just ignore newlines, so you have to be careful where/how you're displaying your multiline text strings. Some components will display it all as one line, some will only display the top line, some will even show \n instead of doing the newline. It all just depends.
    And JTextArea does support word wrapping, so just because it looks like there's a newline, there may not be one.

  • Text Prints as Black Instead of Assigned Swatch

    Hi, I have been having problems with text printing to a HP laser 5500dn printing as black in
    stead of the assigned swatch color.
    I am using CS3 on a Mac.
    It will print fine exported to PDF or printed on an inkjet.
    I have reset preferences.
    In the print dialogue box I have the following settings.
    I DO NOT have "Text as Black" selected.
    Color Management is: US Web Coated SWOP v2
    Color Handling is Let InDesign determine Colors
    Printer Profile is Document CMYK US Web Coated SWOP v2
    Output color is Composite CMYK (Unable to change in this configuration)
    Lastly, after printing and then closing the document,ID asks to save changes, When I cancel and review what edits were done, the last edit comes up as
    "Undo Change Ink"
    I don't know what that means.
    Suggestions?
    Thanks

    Thanks for your help.
    I haven't deleted the swatch or converted to another color.
    Not sure what you mean by aliasing the swatch.
    I did as suggested and looked in the printer setup in the print dialog and did not see anything to print text as black.
    So I ended up changing the text to several different colors and now it prints those colors fine.
    I think the color is so dark as to appear to be black when printing even though it is very apparent on the monitor that it is much different than black.
    I know that monitor colors and printer colors won't match, but this had me very baffled.
    Especially as the PDF printed much differently.
    So I guess I am going to print from the PDF to make sure the colors are as I want them to be.
    I work predominantly on a PC with CS3 that does not have Indesign; the Mac has CS3 with InDesign. The Mac routinely prints all documents much darker than the PC and what is displayed on the screen.
    Thanks, again.

  • How do you set the text of a Hyperlink component in code

    I am using Visual Web pack in NB 6.0. How do you set the text of a hyperlink component in code?
    Please see screenshots at
    http://coba.usf.edu/departments/isds/faculty/agrawal/projects/java/
    I have a hyperlink in a grid panel. I am using
    hyperlink1.setText("Hello"); in prerender(),
    but the Hyperlink shows up with the text "Hyperlink", whereas I was expecting "Hello". However,
    hyperlink1.setUrl("http://www.usf.edu"); works as expected.
    I tried nesting a static text in the hyperlink as suggested in the Creator guide (ed 2, Google project). I deleted the "Hyperlink" text in the properties editor but then the page turned out blank.
    Thanks
    Manish

    Hi Manish,
    Great to know you were able to fix your issue. The following blog entry has the list of resources you would like to look at for future.
    http://blogs.sun.com/NetBeansSupport/entry/useful_resources_for_visual_web
    Thanks
    K

  • How to wrap the text in a label component

    I'm displaying a text in the label component and the output is displayed on the plasma display(It is a java application running on a pc and output is given to plasma display). But the text size is more and getting cut at the edge on the display. How can I wrap the text automatically.

    See
    [http://forums.sun.com/thread.jspa?messageID=10391430]

  • How can I center text in a JTextArea?

    I'm coding my own little font selection frame, and want to display the sample text in a JTextArea, and want to know how I can get the text centered in the field. Does anyone know how this can be done? Thanks.

    Thanks Camrick, I'm disappointed that it will take so much to accomplish this. But I'm very appreciative of your response, and I will definitely put that code to use. Just not in time to turn in my assignment, lol. But thats ok, this function was beyond the requirements anyway, I just wanted to put in some bells and whistles.
    Cheers!

  • Black text prints white

    I finally purchased a copy of iWork '08 and merrily created about 80 slides only when I went to print them out I discovered that the image of the text was in most places white. If the text was in a box it printed and some of the grey text printed along with all text I have set up to fade in or out as the presentation progresses. The details:
    The black text appears in preview but appears white due to the colored background.
    Changing fonts does not help.
    All other programs print fine. I am printing on a Canon MP830, the text does show up on my Laser.
    If I export it to a .pdf the problem follows, even though the text appears on the screen and in preview.
    If I change the color of my text from black to red, or blue it prints fine, shades of grey do not.
    If I export the file to power point and print it from an old version I have in a "Classic" partition running OS 10.4 it prints but when I installed iWork in this partition I get the same result.
    The printer, my software, and iWork has the latest updates installed.
    This is obviously (well maybe not so obviously since it could be a virus no one has caught up with yet) a huge bug in iWork and how it handles black text (I don't know about graphics because there are not black graphics in my slides). I spent several hours reading through the "Discussions" and there are quite a few instances where black text comes out white, blank sheets print out, conversions to .pdf come out with no text ect.
    Does any one know of a work around for this? My only option currently is to fix this or return iWork and go back to Micorsoft with my tail between my legs and purchase Office.

    Presets is set to "Standard" I never changed it. If I select the drop down window there is a choice for "last used settings" and a "Save As".
    I did manage to get my slides printed by saving the file as a Power Point, opening it in a old Office 2001 version of Power Point I have in a "Classic" partition. After a little reformatting they printed perfectly on the same printer. Its kind of sad to have a 8 year old Microsoft program out-perform the latest program from Apple. Of course I will say that using Keynote was enjoyable, but if you can't reliably Print and Export the program is useless no matter how many useful features it comes with.

  • Text prints as bold when it's not bold :(

    Hi,
    I'm using Windows 7 and InDesign CS6. When I print PDF documents from files that have been created in InDesign some lines of the text print out bold when they are not bold and they also look a little fuzzy. I am creating the PDf using the "[High Quality Print]" option. I have tried changing several settings on the printer but nothing makes a difference. The problem doesn't occur when I print in black and white nor does it occur on PDF's I create from word or other applications. Can someone please help? Thanks Mel

    Try updating the driver to a newer version for your printer.
    And if you can get a Postscript Driver for your printer.
    I had a similar issue last year and installing a postscript driver fixed the issue for me.
    What printer are you using?

Maybe you are looking for

  • Not able to get the data in PE51

    Dear Freinds,               I have copied similar to the standard in IN01 , in the Pe51> Windows i have kept under W1 all the wage types which comes under earnings and when i execute the payslip   i.e  in the simulation run and when i view the form i

  • How to sync both from hard drive folders and from Aperture?

    I have the following problem. So far I was syncing photos directly from my hard drive folders and everything was fine. Recently I decided to add some photos from Aperture albums. When I did this all previous photos synced from HD were deleted. When I

  • WHERE ARE MY TABS???? - XPCOM error!!!

    PLEASE HELP!!!!! FIREFOX has deleted ALL my TABS. That is A LONG YEAR OF RESEARCH LOST for trusting this bunch of amateurs who have no clue as to how to run a company and offer NO customer service whatsoever!!! I tried renaming the sessionstore.bak t

  • How can I stop Facebook renaming my contacts?

    I have a Mac running Mountain Lion, an iPhone 4 running iOS 6 and an original iPad running iOS 5. iOS 6 and Mountain Lion brought Facebook integration, which among other things, lets me link the Facebook information of my contacts, with the iCloud en

  • SubFlow best practice advice please

    I am new to IPCCX scripting and would like some advice on whether multiple SubFlows are a good idea. We have 16 small Call Centers that all have very basic scripts. I plan on adding a Holiday/Emergency Closure SubFlow to all of them and I would like