Line up text in a JTextArea

I'm trying to format line up text in columns in a JTextArea. Here is an example of what I'm trying to do.
SubTotal $5.00
Tax $8.00
Total $13.00
I've tried formating the text so that the first work will be a certain length but it still will not line up correctly in the text area because different letters take up different amounts of space. Thanks

change the font of the textarea to monospaced, then append the data
something like in this println
class Testing
  public Testing()
    String pad = "                   ";
    String[][] lines = {{"SubTotal", "$5.00"},{"Tax", "$8.00"},{"Total", "$13.00"}};
    for(int x = 0; x < lines.length; x++)
      System.out.println(lines[x][0]+(pad+lines[x][1]).substring(lines[x][0].length()+lines[x][1].length()));
  public static void main(String[] args){new Testing();}
}

Similar Messages

  • 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.

  • 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

  • Table Cell Editor which allows to input multiple lines of text...

    Hi there
    Does anyone know how to write a table cell editor which allows users to input multiple lines of text? please provide some sample if possible...
    Thanks
    Ken

    I'm assuming you also want the renderer to display multiple lines? if so, make a class that extends JTextArea and that implements the TableCellEditor and TableCellRenderer interfaces, then set instances of this as the editor and renderer for the TableColumn in question. The implementation of most of the methods in these interfaces is trivial, often just this.setBackground() based on the table.getSelectionBackground() or table.getBackground(), a this.setText() based on the value passed in, then just a 'return this'.
    You might want to make an abstract class which implements these interfaces for you, and which delegates to a simple abstract method that you override to return the renderer/editor component.
    Note that you must use two instances of the class you make, one for the renderer and one for the editor, since it must be able to be able to render the remainder of the table's cells without interfering with the JTextArea performing the editing. (alternatively you could make two classes that extend JTextArea, each just implementing one of the interfaces, but this is more effort I think.) Also note that you must increase the table's row height to get more than one row visible.

  • How do I keep account of line and column number within JTextArea?

    How do I keep account of line and column number within JTextArea?
    Thanks.

    hi kamlesh,
    to get the number of columns in a JTextArea u have the function
    getColumns() which gives u the number of columns in the text area.
    To get the number of rows present u have the function
    getRowCount() which returns an int that specifies the number of rows in the text area.
    Hope this helps
    Cheers :)
    Nagaraj

  • Printing two lines of text in Print Module

    Is it possible to print two, or more lines of text, say on a contact sheet, such as filename and caption. If so, how?

    Lightroom automatically wraps text under the thumbnail in contact sheets. The Text Template Editor does not allow you to enter line breaks. So, if your Filename is long enough to fill the first line, the caption will start with the second. If not, you can tweak the template somehow so that it looks the way you want.

  • Document line item text in Clearing document

    Dear All,
    Document line item text
    My client want the vendor invoice line item text(BSIK-SGTXT) to be captured in the corresponding clearing document line item text field(BSAK-SGTXT).
    (i.e) The vendor invoice and its payment clearing document should have the same text in the document line item text filed.
    According to me i can use  a substition rule and a user exit to assign the values. but here comes a problem* i have one clearing document against 3 to 4 vendor invoice documents* so my programming logic has got stucked here? like which vendor invoice line item text the clearing document should pick up?
    is there any other enhancements possible or can some one help me with the programming logic to be applied here.
    Thank you
    Regards,
    Vasanth D

    like which vendor invoice line item text the clearing document should pick up?
    is there any other enhancements possible or can some one help me with the programming logic to be applied here
    Why don't you discuss the issue with your client?  As you said, if you pay 5 invoices in a single run, the payment document item text can't carry all of those texts unless you use the long text.  What is the reason for the requirement?  Perhaps there's another solution.

  • Report for Vendor line item with GL line item text

    Hello SDN,
    We need to add the GL Line item text to a vendor line item report. I don't think adding a GL field is available option in the FBL1N report. Is there a way to display the Vendor name, Vendor number, Open amount and the GL line item text in a report without ABAP invovlement?
    I would really appreciate your help. Thank you.
    Edited by: nsap_fico on Aug 10, 2011 6:29 PM

    Some alternative is in KSB1 (Cost center line item report) - you can change the layout and include offsetting account and its text.
    But, in vendor line item report, if you want vendor number, vendor number, GL account number (offsetting) account and its text, then you should go with abap development.
    Have a look at the following note, if really serves your purpose.
    Note 1504612 - Line items: Offsetting account info (BAdI FI_ITEMS_CH_DATA)

  • How can I make a gray box or gray screen in Pages over a few lines of text?

    How can I make a gray box or gray screen in Pages over a few lines of text?

    Thanks. Almost what I was looking for.
    While that makes for a gray over the lines, it still does not form a box.
    Any other suggestions to form a solid rectangular gray box?

  • How can I change or reduce the line spacing to single in a "multiple lines of text" column in a list?

    We keep many logs in a simple list format. One of the columns requires a description using the "multiple lines of text" default column. Sometimes the person making the entry needs to complete about 20-30 lines of text. Users are requesting we reduce
    the amount of space advanced between lines to save space and be more concise. Is there a way to reduce the line spacing for the column entries to single spacing without code?
    Maree N Percival

    We determined that the site column settings were incorrect for allowing single spacing, we changed the site column setting from "Enhanced rich text (Rich text with pictures, tables, and hyperlinks)" to  "Rich text (Bold, italics, text alignment, hyperlinks)"
    and it is now keeping the text in single spaced lines.
    <label for="onetidRichText">Specify the type of text to allow:</label> 
    <input id="onetidRichTextPlain" name="RichText" title="Plain text" type="radio" value="PLAIN" />
    <label for="onetidRichTextPlain">Plain text   </label>
    <input id="onetidRichTextCompatible" name="RichText" title="Rich text (Bold, italics, text alignment, hyperlinks)" type="radio" value="COMPATIBLE" />
    <label for="onetidRichTextCompatible">Rich text (Bold, italics, text alignment, hyperlinks)</label>
    <input id="onetidRichTextFullHtml" name="RichText" title="Enhanced rich text (Rich text with pictures, tables, and hyperlinks)" type="radio" value="FullHtml" />
    <label for="onetidRichTextFullHtml">Enhanced rich text (Rich text with pictures, tables, and hyperlinks)</label>
    Maree N Percival

  • How copy just line in text file with cat? (SOLVED)

    Hi.
    How i make to copy just only line in text file with cat?
    For example:
    [:0.0]
    file=/home/Arch/./.wallpaper.png
    mode=0
    bgcolor=# 0 0 0
    I want copy just "/home/Arch/./.wallpaper.png" part.
    Actually i want create a shortcut for last wallpaper set from Nitroget, then i put this in SLim background.
    Recently i use hsetroot for wallpaper (~/.wallpaper.png) and i create a shortcut in /usr/share/slim/theme/MYTHEME whith ln -s ~/.wallpaper.png /usr/share/slim/theme/MYTHEME/background.png.
    I want make a same with Nitrogen.
    I now this looks like crazy, but...
    Sorry my English.
    Last edited by kramerxiita (2008-06-04 16:50:48)

    moljac024 wrote:
    kramerxiita wrote:
    moljac024 wrote:How can you make SliM change the background ? You link the theme background to another file ?
    Yes. In theme directory i put background.png shortcut for my wallpaper. So, when a change wallpaper, slim background change too.
    Example:
    ln -s mywallpaper.png /usr/share/slim/themes/default/background.png
    So, Slim background always is my wallpaper.
    So the wallpaper has to be a *.png ?
    No, jpg is possible. But when you create a symbolic link, remember put the extension too. If change png to jpg, change a symbolic link extension.
    But, remember if slim theme directory have background.png and background.jpg, Slim always choice .png. So, put only one this.

  • Smartforms: How to CC email & Include a few lines of Text in Body of email?

    I have created a smartform and have it outputting PDf documents and sending then via e-mail and it all works great.  Except u2026 now I would like to CC someone and also have a few lines of text in the e-mail.  Does anyone have any ideas?
    Here is my code:
    IF p_mail = 'X'.
        wa_ctrlop-device = 'MAIL'.
        PERFORM mail_recipient_object.
        PERFORM mail_sender_object.
        PERFORM mail_appl_object CHANGING g_mail_app_obj.
      ENDIF.
      LOOP AT my_table.
        CONCATENATE 'ECS' comp_year izhr_emp_comp_summary-emp_lname INTO wa_outopt-tdtitle separated by space.
        CALL FUNCTION func_mod_name
          EXPORTING
            CONTROL_PARAMETERS      = wa_ctrlop
            MAIL_APPL_OBJ           = g_mail_app_obj
            MAIL_RECIPIENT          = email_recipient
            MAIL_SENDER             = email_sender
            OUTPUT_OPTIONS          = wa_outopt
            USER_SETTINGS           = u2018Xu2019
          IMPORTING
            DOCUMENT_OUTPUT_INFO    = document_output_info
            JOB_OUTPUT_INFO         = t_otfdata
          TABLES
            I_MYTABLE                 = imy_table
          EXCEPTIONS
            FORMATTING_ERROR        = 1
            INTERNAL_ERROR          = 2
            SEND_ERROR              = 3
            USER_CANCELED           = 4
            OTHERS                  = 5.
       ENDLOOP.
    Determines the Recipent of the E-Mail
    FORM mail_recipient_object.
      CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
        EXPORTING
          ip_mailaddr       = email_address     "E-mail Addr:Input Screen
          ip_type_id        = 'U'               "Internet Address
        IMPORTING
          ep_recipient_id   = email_recipient   "Recipient Obj Key
        EXCEPTIONS
          invalid_recipient = 1
          OTHERS            = 2.
      IF sy-subrc <> 0.
        MESSAGE e531(0u) WITH text-003.                      "Error E-Mailing
      ENDIF.
    ENDFORM.    "mail_recipient_object.
    *Sender of E-mail
    FORM mail_sender_object.
    CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
        EXPORTING
          ip_sender      = sy-uname             "User Logged in
        IMPORTING
          ep_sender_id   = email_sender
        EXCEPTIONS
          invalid_sender = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
        MESSAGE e531(0u) WITH text-e15.                      "Error E-Mailing
      ENDIF.
    ENDFORM.    "mail_sender_object.
    *Creates Mail Application Object to E-Mail Smartform
    FORM mail_appl_object CHANGING g_mail_app_obj.
      SELECT SINGLE * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
      IF sy-subrc NE 0.
        CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'
          EXPORTING
            sapname            = sy-uname
          EXCEPTIONS
            no_insert          = 1
            sap_name_exist     = 2
            x_error            = 3
            sap_name_not_exist = 4
            OTHERS             = 5.
      ENDIF.
      CLEAR sofmfol_key.
      sofmfol_key-type = 'FOL'.
      sofmfol_key-year = soud-inbyr.
      sofmfol_key-number = soud-inbno.
      bor_key = sofmfol_key.
      IF NOT bor_key IS INITIAL.
        swc_create_object folder 'SOFMFOL' bor_key.
        IF sy-subrc = 0.
          swc_object_to_persistent folder g_mail_app_obj.
          IF sy-subrc NE 0.
            CLEAR g_mail_app_obj.
          ENDIF.
        ENDIF.
      ELSE.
        CLEAR g_mail_app_obj.
      ENDIF.
    ENDFORM.    "mail_appl_object.

    Get rid of the smartform-based mail sending code if you can.  That interface is quite old, simplistic, and inflexible (i.e., you can't do what you're asking).  I would use class CL_BCS.  It's especially much easier once you have developed a (custom) standard email wrapper class for sending various types of emails, including smartform-based PDF-attached emails.  You can even go with HTML and dress-up your emails a bit.

  • How do I add space between lines of text in the same cell on Numbers 3.0.1

    I just updated to Mavericks 10.9. In numbers, I used to be able to uncheck a box in the inspector that would make it so the Return key did not move to the next cell, but instead allowed me to add more space between lines of text in the same cell.
    How can I do this in the new version of numbers?

    HI ilb,
    Numbers 3 is a complete rewrite of the application. This preference option hasn't (yet) been included, but N3 is very much a 'work in progress. A word to Apple via Provide Numbers Feedback asking to have this option included in Numbers 3 might be a useful step. You'll find Provide Numbers Feedback in the Numbers menu in Numbers.
    Regards,
    Barry

  • How do I create 2 motion tweens for one line of text?  the text needs to "fly-in-right", I can do that,

    how do I create 2 motion tweens for one line of text?  the text needs to "fly-in-right", I can do that, then it needs to "fly-out-bottom" again, I can do that, but not on the same line of text...any ideas...

    my question
    1- there is any way to assign the Fetch process to specific region so the process take all item in these region only.
    2- how can create manual process to fetch row into specific items in page ( i tray these code
    SELECT col1, col2, col3 ....
    INTO :P1_ITEM1, :P1_ITEM, :P1_ITEM...
    FROM table
    WHERE id = :P_id ) but no data retrieve .
    I do not think that it is possible to have more than one Automated Row Fetch process in a given page. See the thread:
    ORA-01403: no data found : Unable to fetch row multiple automated row fetch
    On your second question, the manual process should work provided:
    P_ID has a value when the process executes. You can do it this way:
    i. Make this process as a on-load After/Before header process
    ii. Make sure that P_ID page item has value when the process executes (set it from another page or before the pl/sql process executes)

  • Display more than one line of text for events?

    I couldn't find this in the forum... I just recently updated to Leopard. Now when I put events in iCal, it only displays one line of text in the month calendar view. I'd really like to see the whole description of the event, even if it's two or three lines. I can't find anything in preferences that addresses this, and various searches are not yielding anything. Help?
    -mel

    Hi there.
    Usually in iCal if you want more than one line of text for timed events, resizing the window will help. Under all-day events, iCal will always show you one line of text, but if there is more space it will show you more text. So, also resizing the window for this will help to see the text.
    Take care.

Maybe you are looking for

  • Itunes won't open get an immediate problem window please help

    I just recently did a complete system restore and have since got everything back together. I just tried last night to re-install intunes first with the start up disc and then through the itunes site. After both times downloading the program with no p

  • JTable Problems - JDK 1.2.2_05a & JDK 1.3.0

    Hi, I have a JTable program that works in JDK 1.2.2_05a but it no longer works when I run the 1.2.2 compiled version in a 1.3.0 environment or compiled and run in a 1.3.0 environment. The problem is that the JTable doesn't accept any keyboard inputs.

  • Currency conversion doesn't work in Hyperion Planning 9.3.1

    Hello, We loaded exchange rates in Planning and when we launched a refresh of the database, exchanges rates are not transferred to essbase, as it is supposed to do according to the admin guide. Do we need to do something special to have the exchange

  • User Exit/ BADI to validate input in LT06

    Dear Gurus, I would like to ask what user exit/BADI i could use to validate or check the input value before creating the material document in LT06? I have tried MWMTO001 and put break point inside FM EXIT_SAPLL03T_001, but the break point is not call

  • Using a Datagrid in a New State

    Is it possible to put a datagrid in a new state? Everytime I try I get a parser error in the code. I am trying to have the datagrid pop onto the scren after a selection is made which is why I am putting it into another state. Thanks. Dave