How to embed string into rectangle?

Hi all.
I have a rectangular area to draw the string, but the string can be wider than the rectangle it should fit. How to draw truncated string? For example:
public void paintComponent(Graphics g) {
          String s = new String("This is a very long string");
          int x = 0;
          int y = 0;
          int rectWidth = 20;
          int rectHeight = 10;
          Rectangle r = new Rectangle(x, y, rectWidth, rectHeight);
          int strWidth = g.getFontMetrics().stringWidth(s);
          if (strWidth > rectWidth) {
               System.err.println("How to do that?");
          } else {
               g.drawString(s, x, y);
     }Thank you in advance.

If what you want is for your clipped string to display the "..." just like JLabel does, here is an algorythm that you can use:
1- If the font metrics tells you that your string is going to get clipped, start removing chars from the end
2- add "..." to the shortened string.
3- if that string now fits, done
4- else goto 1

Similar Messages

  • How to embed html into keynote

    I want to embed the youtube code for a vid into my keynote presentation so when I export to flash I can post the entire thing online, the presentation will work and I can watch the vid too. Any thoughts on how to embed html into a keynote page?
    Thanks,
    Jeremy

    The only way to get video out of Keynote that I know of, is the QuickTime export. Now, if you use another tool after that (to convert the QuickTime video) that might be able to work for you.

  • How to embed excel into a region on portal AS

    How to embed excel into a region on portal AS??
    Any suggestions will be appreciated...

    Hmm. topic is from 2005. But havent they gotten something better than iframes since 2005??? I find iframes not flexible enough to paste in portlets, made by, say mod_plsql into a article publisher tool.
    For example, I want to make an article using my companies article publication tool (Intranett publisher) saying..
    Blah blah blah
    If you look at the table below u see the current data updated every hour:
    <iframe call to portlet with data>
    This data is blah blah blah etc
    When I use iframe I have to set the size (I dont know how big table will be in the future), and get ugly borders with scrollbars if I dont set size right. Isnt it any better code out there yet? Hopefully as easy as embed pictures from the outside.

  • How to embed music into adobe muse

    I wanna make a website for a musician and I'm wondering how to embed mp3 songs on the website.
    Thanks

    Hi ritasaluix,
    Please refer to the following threads:
    Re: How to add audio into Muse (not in the background)?
    Re: how do i embed audio (mp3) in muse?
    Regards
    Sonam

  • How to convert string into date

    Hi all,
    I m new to JDeveloper
    I m taking the date as a string then passing it as a string in the method.
    I want to convert tht string into the date of format (DD-MON-YYYY) or any other format
    require yur assistance in this job.
    THANKXX in advance
    ankit

    Is this what you are looking for:
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd-MMMMM-YYYY");          
    java.util.Date date1 = null;
    try
       date1 = formatter.parse("Thu Jun 3 09:09:30 2004");
    catch(Exception e)
       e.printStackTrace();
    System.out.println("Date1 in millis : " + date1.getTime());
    System.out.println("Date1 in string : " + date1);
    java.util.Date date2 = new java.util.Date(date1.getTime());
    System.out.println("Date2 in string : " + date2);or look at http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html for more options

  • How to embed audio into an image?

    Hi there,
    I'm trying to embed audio into an image so that clicking on the image plays the audio.  I've tried adding a behavior to the image but it doesn't seem to work.  Any thoughts?
    Denbeck

    You might be able to do something convoluted and complicated with JavaScript.  The HTML4 standard is designed around text, not movies and audio.  So I actually wouldn't expect DreamWeaver to be able to do this.
    If you don't have Flash, You should look online for FREE or reasonably priced Flash Slide Shows.  There are dozens of them, and some can play audio while showing a picture.
    Otherwise, if you do have Flash, someone on the Flash forums could probobaly give you a couple lines of action script code or a quick flash tutuorial and you will be done in no time.
    So to answer you question.  You can't embed audio into an image with DreamWeaver, or any other HTML editor for that matter.   Your best option is to use Flash.

  • How to embed font into PDF - Listener 2.0.2 FOP configuration

    I need to embed custom font into PDF report in order to print one of Slovenian characters: Č (C with caron) This character shows as # sign when I generate standard PDF report using Apex 4.2.2 and Listener 2.0.2. As far as I understand 14 native Adobe PDF fonts are based on Windows 1252 encoding. This encoding doesn't include mentioned Slovenian character.
    Oracle White paper http://www.oracle.com/technetwork/developer-tools/apex/learnmore/custom-pdf-reports-1953918.pdf says:
    "APEX Listener 2.0.2 supports only the Base-14 fonts. To configure additional fonts, see this document: Apache(tm) FOP: Fonts "
    I was able to embed my custom font into standard Apache FOP report server. Solution consist of saving two files my_font.ttf and my_font.xml to server and update of FOP userconfig.xml file (fonts part where path to saved 2 files have to be specified)
    How can I do this on Apex Listener 2.0.2 ? Where is located userconfig.xml file?
    Simon

    Hello Ivaylo Mutafchiev,
                                           There is no way we can control the fonts in the created PDF / while creating the PDF using the class cl_document_bcs in your PDF creation logic.
    You can try some other approach of creating PDF from the Smartforms OTF stream data .
    Try using the follosing FM for the PDF creation and sending email:
    CONVERT_OTF_2_PDF
    CONVERT_OTF_AND_MAIL
    SO_OBJECT_SEND
    CONVERT_OTF_AND_MAIL_NEW (Try this but this FM still uses  the class that you are using currently. But give it a try and see the results)
    Hope this answers your question.
    Thanks,
    Greetson

  • How to embed font into generated PDF?

    Hi,
    I have an issue with cyrillic fonts in PDF-file, generated from smartform using the following mechanism:
    1. Run FM for smartform with ==> getotf = 'X'
    2. Perform CONVERT_OTF retrieving result into a XSTRING.
    3. Converting xstring content into a table using "cl_document_bcs=>xstring_to_solix).
    4. Creating mail to an external internet user with attached pdf ==> using "cl_document_bcs=>create_document..."
    Smartform contains cyrillic content, based on HELVCYR (Helvetica cyrillic) font. Application server is based on Windows.
    Everything worked well (for months!) for allmost all of the clients of our customer. Of course, some of clients have different OS-es (such as Linux, Mac OS, etc.), and then the problem starts - they doens't view properly the cyrillic content. English content (even numbers, etc.) are properly displayed. We found what fonts are used in the PDF, but my questions are:
    1. Is it possible to embed the font into generated PDF-content?
    2. If no, is it possible to generate PDF-content non-selectable (i.e. in some image mode) ?
    If yes, how to do this?
    Or is there any other way to workarround this issue - to be able to display mail with attached PDF-content with cyrillic on different OS-es? It would be better if it is possible without calling external converter...
    Any help would be highly appreciated.
    Thanks in advance.
    Regards,
    Ivaylo Mutafchiev

    Hello Ivaylo Mutafchiev,
                                           There is no way we can control the fonts in the created PDF / while creating the PDF using the class cl_document_bcs in your PDF creation logic.
    You can try some other approach of creating PDF from the Smartforms OTF stream data .
    Try using the follosing FM for the PDF creation and sending email:
    CONVERT_OTF_2_PDF
    CONVERT_OTF_AND_MAIL
    SO_OBJECT_SEND
    CONVERT_OTF_AND_MAIL_NEW (Try this but this FM still uses  the class that you are using currently. But give it a try and see the results)
    Hope this answers your question.
    Thanks,
    Greetson

  • How to embed applescript into a shell script for notification center

    I have managed to cobble this together:
    You can run it in your Terminal, it is harmless, and will output results that will show you a notification from notification center:
    I have items on my pasteboard as the results of a script, I want to pbpaste them into the below command, but can't get the syntax right.  I am not objectionable to string concatenation and building or whatever it takes.
    osascript -e 'display notification "The url(s) are on your clipboard from my.app" with title "my.app has finished" subtitle "Some Sub title"'
    Ideally, I want to put `pbpaste` in the "Some title" section, but I get the literal string. I try creating a variable, and get that literal string.
    I tried building the entire string up as one variable, which in the Terminal echo'd out and works, but in Notification Center, I get the actually literal variable.  It's mainly a bash script, so the context witch to AppleScript i being a pain in the rear.
    Suggestions? Any master out there that this makes any sense to?

    As it stands, and the way you have your notification structured, this is the output from the notification center. I did an echo "From the clipboard" | pbcopy before I ran the following script. It uses a Bash function, osascript HERE document, and shows how to pass variables to the function, and receive them in AppleScript. If you want substring text that is not the result of pbpaste, then you can either make the string inside the AppleScript, or pass the string in as a variable.
    To get this output, I used the following Bash/Osascript combination:
    #!/bin/bash
    #osascript -e 'display notification "The url(s) are on your clipboard from
    #my.app" with title "my.app has finished" subtitle "Some Sub title"'
    function notification () {
      `osascript <<-AppleScript
            set txt1 to "The URL(s) are on your clipboard from "
            set txt2 to " has finished"
        set appName to "$1" as text
        set subStr to "$2" as text
        set noteStr to txt1 & appName
        set titleStr to appName & txt2
        tell application "System Events"
            display notification noteStr with title titleStr subtitle subStr
            delay 1 -- give notification time to fire
        end tell
        return quit
    AppleScript`
    appName="foo.app"
    #echo $appName
    subTitle="$(pbpaste)"
    #echo $subTitle
    notification "${appName}" "${subTitle}"
    exit 0

  • How to embed BARCODE into smartform ?

    Hi All,
         I have a requirement to embed an EAN-128 barcode for handling unit(EXIDV) and other fields in a shipping label(smart form).please let me know how should I send the value for these
    ·       start code
    ·       FNC1
    ·       application identifier
    ·       data
    ·       checksum
    ·       stop code
    Parameters?
    I have created a Z-Barcode format with Bar Code Symbology: Code 128 and I am planning to  use it to create EAN128 format is it correct?

    Hmm. topic is from 2005. But havent they gotten something better than iframes since 2005??? I find iframes not flexible enough to paste in portlets, made by, say mod_plsql into a article publisher tool.
    For example, I want to make an article using my companies article publication tool (Intranett publisher) saying..
    Blah blah blah
    If you look at the table below u see the current data updated every hour:
    <iframe call to portlet with data>
    This data is blah blah blah etc
    When I use iframe I have to set the size (I dont know how big table will be in the future), and get ugly borders with scrollbars if I dont set size right. Isnt it any better code out there yet? Hopefully as easy as embed pictures from the outside.

  • How to Embed ALV into viewcontainerUIelement Programatically in Webdynpro

    Hi Experts,
    I want to embed an ALV into viewcontainerUIelement programatically, i.e, I create the ViewContainerUIelement at the runtime and embed an ALV at runtime. Is this possible? If yes then how.
    Regards,
    Biswajit

    Hi ,
    [http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/80a3de18-ee00-2d10-bfb3-946d7e00fd91]
    Please refer to this article for dynamic alv with code.
    regards
    Kuldeep

  • How to save string into memory

    For example...I have some web address stored as string, and i want to write it into memory (just like ctrl+c when you copy some link), so then i can just go to Firefox, and simply ctrl+v to the address bar. Any ideas? Thanks.
    I've add this topic to swing because i want to copy link to memory via right-mouse-click which opens some pop-up menu and there is item called "copy link", but i dont know how to implement this operation..
    Edited by: Lukasito on Nov 11, 2009 8:20 AM

    [http://www.exampledepot.com/egs/java.awt.datatransfer/ToClip.html]

  • How to embed data into an InDesign Document

    Hello everybody,
    I'm porting a QuarkXTension to InDesign CS3 on PC but, maybe, I've found a showstopper...
    The current xtension writes some collected data into a document slug that is retrieved by an external application simply scanning the content of the file.
    I need to maintain the same way with InDesign but I've discovered that the persistent data added to a document workspace doesn't stay all together when is more than few KBytes (everything seems to be ok until 2 KBytes but that's too little) inside the InDesign document but is scattered on many locations. Of course this makes the work of the external application impossible.
    Is there any way to command/force inDesign to write the persistent data insidde the file in one single chunk?
    I understand this is something unusual but that's the way that complex publishing workflow works and can't be changed in that part.
    Thanks a lot in advance for any help.
    Best regards,
    Luca Severini

    I think I have found a possible solution to embed my data in a way readable by an external application. To use the XMP toolkit.
    Very interesting the fact XMP Toolkit includes the source of a simple command line tool that parses the xmp embedded into InDesign file.
    The same source can be easily modified to get all the objects contained in the document aka database.
    Bye
    Luca

  • How to embed audio into file for export to pdf

    Hello, I've transcribed a two-hour lecture and copied it into Indesign.  I would like to create a pdf with the audio of the lecture embedded in it so that when the reader clicks on a paragraph or a button the audio for that particular sentence or section starts up. The point is to allow the reader ready-access to the audio that corresponds with the transcript. Ideally the reader could click anywhere in the text and the audio would start there.  Does anyone have any suggestions for making this kind of document? much appreciated.

    no pardon necessary! i need to embed the audio file because it contains the original lecture, that's what I want the reader to have access to while reading the transcription, since the transcription is not meant to substitute for but rather supplement the audio. for example, in the transcribed text I have put "[...]" for segments of the recording that are inaudible. If I put the original audio into the file then the reader has the option of going to that specific section and listening to it themselves. basically i want to create a pdf document of a lecture. I want to be able to highlight important parts of the lecture, search the lecture for key-words, and scan it quickly for specific items of interest, but I also want easy access to the original audio because tone of voice isn't translatable into text (and the tone of voice in this case is important for meaning), and because there are many segments that I couldn't hear, so I'm trying to figure out the best way to link sections of the text to specific sections of the audio.

  • How to convert string into date datatype

    hi! there
    i've a date in string format like MM/dd/yyyy
    eg:String sDate = "01/30/2002";
    and i want to convert this string format into java date format
    same as 01/30/2002 only
    when i write like this
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy");
              String sDate = "1/11/2002";
              java.util.Date oDate = formatter.parse(sDate);
    i'm getting the output
    Fri Jan 11 00:00:00 GMT+05:30 2002
    i just want the out put like 01/30/2002
    plz,help me

    Hi,
    Just use back the SimpleDateFormat object you defined.
    String myDateInStr = formatter.format(oDate);
    this will format a java.util.Date object to a string representation according to the format you specified in the instantiation of SimpleDateFormat object.

Maybe you are looking for

  • Best practice for data persistance for monitoring without BAM

    Greetings, We are modeling a business process in a large organization using BPEL Process Manager. The key point is that business people needs to monitor the execution of the business process in several key sectors of the process execution as well as

  • Numerous problems with the Adobe AIR runtime for Android

    I created a app on the platform Adobe AIR for Android, which requires for AIR. The app is very popular in the Android Market, but many users complain of problems with the installation of Adobe Air runtime. For example these phones users: LGE LG-P698,

  • Flash player crashes after few secs/mins

    Hello everyone for last 3 days im experiencing this annoying issue with flash player. Basically whenever i turn on the video/stream/even pages with adds the flash player crashes. I tried so many things past 3 days. Heres the list: 1st of all i tried

  • Can developers create apps with lock screen buttons?

    Title pretty much says it all.  Is it possible for developers to create apps that have lock screen buttons that appear with a home button double tap similar to the itunes control buttons?  I've seen other apps tap into itunes media controls but can y

  • Can it be taken apart?

    Hi everyone! My Airport Express has an issue... the last time I had a set of RCA cables going from the phono jack to my stereo, the end of the phono plug broke off inside of the jack on the airport express and now I can't use my airtunes because the