Putting long strings on a JLabel

I want to write a string on a particular rectangular region (e.g. JLabel) and the length of string is more than the width of the rectangle, so it wont fit in one line.
Is there any API that will automatically calculate where to put the line break and display it accordingly in multiple lines.
In other words, I want Java equivalent of VC++ function
Status DrawString(
const WCHAR *string,
INT length,
const Font *font,
const RectF &layoutRect,
const StringFormat *stringFormat,
const Brush *brush
);

Other than using an uneditable JTextArea (as suggested above), not APIs exist to do it automagicly.
You would have to use things like getStringBounds , adding one word at at time, until you go over the length you want, then roll back a work, add a new line, and do it all again.

Similar Messages

  • GP - How to display a long string value

    I'm trying to display a really long string value and then allow the user a couple of result state choices (to either go back and do another search or finish).
    None of the forms (WD, display, etc.) will display a really long string.
    I tried using a loop type decision dialog, but there doesn't appear to be a way of having it pick up a parameter value as the message (or part of the message) to display.
    I can get it to display in the complex type decision dialog, but I don't need the group/options and I can't seem to get rid of the second set of buttons that show up (the long string parameter value was put into the 'Info Texts' area and does display ok).
    Is there any easy way of displaying the complete contents of a long string value and have buttons for results states?  I'd even be happy if I could just display the whole string and use a separate callable object for the choices.
    Thanks,
    Cindy

    I think you should try calling a JAVA or ABAP Webdynpro as the callable object. As you know, we can display long texts in the webdynpro fields. Other alternative is an Adobe form as well.
    Cheers,
    Mandrake

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

  • How to put a String into a byte array

    How can i put a String into a byte array byte[]. So that i can send it to the serial port for output to an LCD display. Cheers David

    javadocs for String
    getBytes
    public byte[] getBytes()
    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
    Returns:
    The resultant byte arraySince:
    JDK1.1

  • How to put a string from one Frame to another Frame?

    Dear all,
    How can I put a String from one Frame to another Frame?
    When the application started, the Frame 'WindowX' will be displayed. After you press the 'openButton', a whole new Frame (inputFrame) will be shown. In this Frame )(inputFrame) you can write a String in a TextField. After pressing the okButton, this String will be sent to the first Frame 'WindowX'.
    But does anyone know how to realize the sending part?
    I've tested this code on Win98 SE and JDK1.2.2.
    Hope someone can help me. Thanks in advance.
    import java.awt.*;
    import java.awt.event.*;
    public class WindowX extends Frame implements ActionListener, WindowListener
         private Button openButton;
         private TextField resultField;
         public static void main(String [] args)
              WindowX wx = new WindowX();
              wx.setSize(300,100);
              wx.setVisible(true);
         public WindowX()
              setLayout(new FlowLayout());
              openButton=new Button("open");
              add(openButton);
              openButton.addActionListener(this);
              resultField=new TextField(10);
              add(resultField);
              resultField.addActionListener(this);
              addWindowListener(this);     
         public void actionPerformed(ActionEvent evt)
              if (evt.getSource()==openButton)
                   inputFrame ip=new inputFrame();
                   ip.setSize(200,80);
                   ip.show();
         public void place(String theString) //this doesn't work
              resultField.setText(theString);
         public void windowClosing(WindowEvent event)
              System.exit(0);
         public void windowIconi......
    class inputFrame extends Frame implements ActionListener,WindowListener
         String theString = "";
         Button okButton;
         TextField inputField;
         WindowX myWX=new WindowX();   //??
         public inputFrame()
              setLayout(new FlowLayout());
              inputField=new TextField(10);
              add(inputField);
              inputField.addActionListener(this);
              okButton=new Button("OK");
              add(okButton);
              okButton.addActionListener(this);     
              addWindowListener(this);     
         public static void main(String[] args)
              Frame f = new Frame();
              f.show();
         public void actionPerformed(ActionEvent evt)
              if (evt.getSource()==okButton)
                   theString=inputField.getText();
                   myWX.place(theString);   //??
                   dispose();
        public void windowClosing(WindowEvent e) {
        dispose();
        public void windowIconi......
    }

    Thanks for your reply!
    But I got an other problem:
    I can't refer to the object (wx) made from the main Frame 'WindowX', because it's initialized in 'public static void main(String [] args)'...
    Hope you can help me again... Thanks!
    import java.awt.*;
    import java.awt.event.*;
    public class WindowX extends Frame implements ActionListener, WindowListener
         private Button openButton;
         private TextField resultField;
         public static void main(String [] args)
              WindowX wx = new WindowX();   //!!
              wx.setSize(300,100);
              wx.setVisible(true);
         public WindowX()
              setLayout(new FlowLayout());
              openButton=new Button("open");
              add(openButton);
              openButton.addActionListener(this);
              resultField=new TextField(10);
              add(resultField);
              resultField.addActionListener(this);
              addWindowListener(this);     
         public void actionPerformed(ActionEvent evt)
              if (evt.getSource()==openButton)
                   inputFrame ip=new inputFrame(wx);
                   ip.setSize(200,80);
                   ip.show();
         public void place(String theString)
              resultField.setText(theString);
         public void windowClosing(WindowEvent event)
              System.exit(0);
         public void windowIconi....
    class inputFrame extends Frame implements ActionListener,WindowListener
         String theString = "";
         Button okButton;
         TextField inputField;
         WindowX parent;
         public inputFrame(WindowX parent)
              setLayout(new FlowLayout());
              this.parent=parent;
              inputField=new TextField(10);
              add(inputField);
              inputField.addActionListener(this);
              okButton=new Button("OK");
              add(okButton);
              okButton.addActionListener(this);     
              addWindowListener(this);     
         public static void main(String[] args)
              Frame f = new Frame();
              f.show();
         public void actionPerformed(ActionEvent evt)
              if (evt.getSource()==okButton)
                   theString=inputField.getText();
                   parent.place(theString);
                   dispose();
        public void windowClosing(WindowEvent e) {
        dispose();
        public void windowIconi..........
    }          

  • Inserting long string into Oracle

    When my code inserts about 5K character into a table, I got an error message saying that the Oracle could only handle 4K character. I am currently looking at LOB but havn't had a clear idea yet. Could someone give me some help on this? According to the sample code, I will have to use Oracle JDBC driver for LOB. But we are using BEA's Kona driver for all JDBC connections. Is there an easy way to insert long string?

    hii
    nams u solve ur problem using setCharacterStream method
    but it does't work if the string more than 4000 char
    raises "java.sql.SQLException: Protocol violation"
    here's the code
    PreparedStatement ps = con.prepareStatement( "UPDATE candidate SET cv_new = ?");
    StringReader cvReader=new StringReader(cv_new);
    int abc=cv_new.length();
    ps.setCharacterStream( 1, cvReader, abc);
    ps.executeUpdate();
    is that any problem in that code or it's a jdbc driver broblem ??
    i'm using classes 12.zip
    thanks

  • How to find out if a long String has a "subString" twice or more.

    I need to find out if a long String has the same number twice or more.
    I need to look matches for numbers running from 000, 001....999 and if a number is found twice or more, return that number and lines there were found.
    example String:
    -;000 ; 1 ; 2006-12-11 ; -; job;
    x;001 ; 2 ; 2006-12-11 ; 2006-12-12; do this
    -;002 ; 3 ; 2006-12-11 ; -; work
    -;003 ; 0 ; 2006-12-11 ; -; some
    -;004 ; 2 ; 2006-12-11 ; -; thing
    x;005 ; 1 ; 2006-12-11 ; 2006-12-11; reads
    -;003 ; 0 ; 2006-12-11 ; -; here
    Should return from example String:
    003 at lines 4 and 7
    Any ideas?

    So there are newlines in the String?
    You could use a StringTokenizer to break the String into lines, then searching on each line if it contains any of the search strings. (You need to clarify if a line can contain more than one search string).
    Probably you should use a Map<String, Integer> to record the searchcounts.
    Or an int[] Array if you are really sure that the Strings you search for really are numbers.
    Another option is to use:
    LineNumberReader lnr = new LineNumberReader(new StringReader(searchString));This will save you from explicitly having to take care for the line number.
    In any case your example looks like the individual lines are semicolon separated fields and the numbers you search for always are in column two.
    So after breaking up the original String in lines, you could use another StringTokenizer to break up the line in fields.

  • In report layout, can format a long string display as Column mode?

    Hi,
    Just want to check in report builder any way can format a long string into a column mode?
    Example: I have a field to hold 8000 character, and would like to print
    30 character in each line, when reach 50 line, then print in column i/o to print next page?
    Any idea ? Thanks a lot if you can share your experience with me.
    best Regards,
    Klnghau

    hi let say your field name is x
    then if your want it word wrap then it's simple just get one field and make it's vertical
    elasticity variable. and asign the field to it..
    but if you want your field to be displayed as
    first colunm and then beside continuation of that column but in 2nd one...
    then create 2 formula columns make your field legth been distributed half in each.
    so cf_1 is:
    decalre
    t varchar2(1510);
    begin
    if length(:x) > 1500
    t := substr(x, 1, 1500); -- as 30 x 50 = 1500
    else
    t := :x;
    end if;
    return t;
    so cf_2 is:
    decalre
    t varchar2(1510);
    begin
    if length(:x) > 1500
    t := substr(x, 1500, length(:x)-1500); -- as 30 x 50 = 1500
    else
    t := '';
    end if;
    return t;
    and then in design view
    field1 field2
    for field1 source is cf_1 and
    for field2 source is cf_2
    that's all
    Enjoy Oracle...

  • Problem in displaying long string in JTextField

    Hi All,
    I got problem in displaying long String in JtextField. It does center alignment & I can see middle part of string where length of JTextfield is 6 char. How can I do left alignement so that I can see starting 6 character?
    --Harish                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    you may try this:
    yourTextFieldName.setHorizontalAlignment(JTextField.LEFT);
    or
    yourTextFieldName.setHorizontalAlignment(JTextField.LEADING);
    hth.

  • OWA Email - One Long String

    The email I receive from OWA has no line breaks, it is all one long string.  This is creating a big problem when I forward the emails received with my BB as they are difficult to read by the recipient.  Is there anyway to correct this?  I use BIS and access my work email via OWA.  I also have a separate personal email set up with no problems with the email I receive or send.  
    BB Curve 8310 v4.5.0.55
    OWA v5.5 SP4
    Any help will be appreciated!

    I'm experiencing the same issue (no line breaks) when pasting rows directly from Excel (2008 & 2011) into a Flex TextArea on a Mac. However, when pasting the exact same data from a Windows Excel spreadsheet, it contains the line breaks.
    From Mac: Customer\tPhoneCustomer 1\t555-555-5555Customer 2\t555-555-5556
    From Windows: Customer\tPhone\rCustomer 1\t555-555-5555\rCustomer 2\t555-555-5556\r
    This appears to be a bug in a flash.display class as pasting the data from Excel to a text editor and then copying/pasting into the same Flex TextArea preserves the original line breaks.
    Has anyone figured out a work around?

  • When I forward an e-mail, I get a long string of gobblygook that goes with it and I cannot figure out how to eliminate it without having to delete it every time

    When I forward an e-mail, I get a long string of gobblygook that goes with it and I cannot figure out how to eliminate it without having to delete it every time I forward an e-mail. The following is only part of the string that I am talking about. How can I eliminate this from the e-mail?
    Here is part of an excerpt from one of the strings:
    From: - Mon Aug 19 18:12:47 2013
    X-Account-Key: account1
    X-UIDL: 065B31352CC6B3C0789DEA7954395B55
    X-Mozilla-Status: 0001
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Return-Path: <[email protected]>
    Received: from hrndva-mxlb.mail.rr.com ([10.128.255.126]) by hrndva-imta07.mail.rr.com with ESMTP id <20130819211326470.DBUO12525@hrndva-X-Roving-StreamId: 0

    Sorry, Firefox doesn't do email, it's strictly a web browser.
    If you are using Firefox to access your mail, you are using "web-mail". You need to seek support from your service provider or a forum for that service.
    If your problem is with Mozilla Thunderbird, see this forum for support.
    [https://support.mozillamessaging.com/en-US/home] <br />
    or this one <br />
    [http://forums.mozillazine.org/viewforum.php?f=39]

  • How can I copy a long string of texts from my iPhone 4s to a word document?

    I need to copy a long string of texts to a word document on my PC.

    One method would be to use 3rd party software. The following is one example but there may be better/cheaper or even free options: http://www.wideanglesoftware.com/touchcopy/

  • Long strings in combo box

    I have an editable combo box that I'm sticking in a compact spring layout. The problem is if you use a list that contains very long strings (like a long hex string), the combo box sizes itself to fit it and all the other controls are made to be that length as well. Is there a way to stop the control from becoming so long, like a horizontal scroll bar in the list?

    Read this [url http://www.objects.com.au/java/examples/src/examples/SteppedComboBoxExample.java]example
    Here's its [url http://www.objects.com.au/java/examples/swing/SteppedComboBox.do]picture
    ICE

  • How to indent the 2nd line of a long string?

    Hi all,
    I would like to achieve something like below where the 2nd line will be indented automatically. How to do format this in Oracle Report? The "<--indent-->" below is to illustrate the indentation, which I can't show in this posting as the formatting is not supported.
    Okuda, M., & Okuda, D. (1993). Star Trek chronology: The history of the
    <--indent--->future. New York: Pocket Books.
    Please advise.
    Thank you.

    Yes, chr(10) can make the string break to next line, but that cannot fulfill my requirement.
    What I need is a single long string that will automatically get indented for the 2nd line onwards when display in report.
    I can't use chr(10) because I won't know when to break to next line because it does not have fixed rule that after which part should I break it to next line. I'm referring to bibliographic citation that normally display as indented for the 2nd line.
    Hope you got what I mean.

  • Automatic trim of too long strings

    Hi,
    if I try to insert a too long string value into a VARCHAR column, I get the error ORA-12899.
    Is it possible to set the Oracle database so that too long strings get trimmed automatically?
    Thank you.

    Hi,
    Welcome to the forum!
    Unfortunately, there's nothing quite like what you want in Oracle.
    Even if you write a trigger to cut off the excess, you can still get the ORA-12899 error. For example, if table_x.col_1 is defined as VARCHAR2 (10), this statement:
    INSERT INTO table_x (col_1) VALUES ('ABCDEFGHIJKLMNOP');will get the error, even if you have a trigger that says
    :NEW.col_1 := SUBSTR (:NEW.col_1, 1, 10);You could define col_1 as VARCHAR2 (4000), and have a trigger that includes the statement show above, to make sure that the actual values will be 10 characters or less. You cound even have a CHECK constraint (LENGH (col_1) <= 10).
    Think carefully about what Someoneelse said. Do you really want to throw away part of what users enter, automatically and without any warning? Will that cause confusion?

Maybe you are looking for

  • Italic font on mac os 10.3.9 (panther)

    Our application uses a customized table cell renderer to show italic fonts for non-ediable rows. It works fine on Mac OS 10.4 (Tiger), but not on 10.3.9 (Panther). The renderer just shows plain text for the rows, rather than Italic. I have found this

  • Apps on Blackberry App World

    I am a long time user of blackberrys, but one flaw that seems to me as very important is the lack of variety of apps on the Blackberry AppWorld. Useful Apps are available on the iTunes Appstore and even the Android store but are not available on the

  • Troubleshooting "error generating preview" in Installer

    From time to time, I have run into this maddening condition where I build an installer and it will not run because it reports "error generating preview" errors on the EXE for which I am trying to build the installer.  Most often, I can build the EXE

  • Reuse FPM configuration in another webdynpro component

    Hello, I would like to define the navigations and buttons in one component configuration . And then use this  in another webdynpro component.  As the buttons/navigation is applicable to multiple requirements. So I would like to reuse it. I tried to d

  • Replacing coulour

    I have converted a colour image to black & white. I need to replace the coulour back into part of the image, I have tried using a mask in the black and white adjustment layer,using the brush tool  but nothing is happening, what am I doing wrong?