Setting Text over an Icon which is on a JLabel - Urgent

Can someone help me. I need to set some text over an Image/Icon which is placed over a JLabel.

You should simply change the iconTextGap value (according to the string width and the icon width if you want it centered) :
          JFrame frame = new JFrame("Centered label");
          JLabel label = new JLabel("centered label",new ImageIcon("im1.gif"),SwingConstants.LEFT);
          frame.getContentPane().add(label, BorderLayout.CENTER);
          frame.pack();
          frame.setVisible(true);
          int iconWidth = label.getIcon().getIconWidth();
          Font font = label.getFont();
          Graphics g = label.getGraphics();
          FontMetrics fm = g.getFontMetrics();
          int stringWidth = fm.stringWidth(label.getText());
          label.setIconTextGap(-stringWidth+((stringWidth-iconWidth)/2) );
I have made the frame visible before setting the texticongap because you can't get the graphic context of a component if this component is invisible.
Now the label is perfectly centered on the icon.
I hope this helps,
Denis

Similar Messages

  • Setting Text on a JLabel which has an Icon on it

    I have a JLabel, on which I have set an Icon. I now want to place some text over this Icon. How do I go about achieving this??

    use setText(String) in combination with setVerticalTextPosition(JLabel.TOP)

  • Can you extend multiple over set text boxes at once?

    I am in the process of changing many large Indesign files from MAC to PC which has created, in some cases, hundreds of over set text boxes.
    I'm looking for a faster way of fixing these files as extending each of these text boxes one by one is taking up a lot of time. I am currently using the pre-flight panel.
    I have Indesign CC 2014.1.

    Not the answer to your question, but merely moving from Mac to PC should not be causing text to go overset. Seems likely you've got a font substitution, or perhaps you've also changed the version of ID, or both.
    Do you have an object style assigned to the text frames? Perhaps redefining the style to include auto-sizing will solve the problem.

  • Is there a way to remove the text that appears over dock icons when the cursor is over them?

    Is there any way to remove the text that appears over dock icons when you hover over them?  Or at least make it time out, or become more transparent?

    You can do that with the Menu Editor extension - https://addons.mozilla.org/firefox/addon/menu-editor/
    This extension has not been updated by its author in a couple of years, but another developer has updated it for Firefox 4, you can get the updated version from http://netticat.ath.cx/MyAddons/MyAddons.htm#3rdpartyaddons

  • TEXT Messaging: I no longer have an icon which allows me to attach an image

    For some reason when I open text messaging the icon that had been located to the left of the text entry window has disappeared... also where the text entry box used to have a top subject entry are and a lower message area it is now all one white entry box.
    Any idea why this might be happening?

    Settings > Messages > MMS Messaging "ON"
    Settings > Messages > Show Subject Field "ON"
    -SM

  • Text based VI Icon editor with letter compression

    For anyone who is looking for a quick and easy text based icon editor I've posted my latest version in the LAVA CR
     http://forums.lavag.org/downloads.html&showfile=56
    Description:
    This is the second version of my vi icon editor and was created in LV8.2. The purpose is to help quickly create text base icons. The editor can be used in place of the standard NI icon editor or as a stand alone vi. see instructions. My original posting of the icon editor Ver. 1 can be found here
    LabVIEW 7.0,7.1 http://forums.lavag.org/index.php?s=&s...ost&p=19022
    LabVIEW 8.0 http://forums.lavag.org/index.php?s=&s...ost&p=12920
    Instructions:
    1: The icon editor was designed to be used as a replacement for the standard NI editor LV8.x only. To get LabVIEW 8.x to use the editor place the three files (lv_icon.vi, color templates.bin and the folder lv_icon_Subvis) in the LabVIEW 8.2\resource\plugins directory.
    The next time the icon editor is called LabVIEW will use the lv_icon.vi instead of the standard one.
    There is a button on the editor that will allow you to use NI’s editor when a text icon is not desired.
    2: The icon editor can also be called from another vi or used as a stand alone tool. Make sure the “From Editor” control is set to false either via terminal in the lower left corner of the connector pane or manually in the FP. This setting indicates to the vi that a vi reference will be used to extract and save the icon information. If the “VI REF” input control is invalid at runtime a dialogue box will appear asking the user to select a vi.
    New features:
    Along with the auto drawing and Text compressing from version 1, version 2 has 2 new features.
    1: In addition to the 2 color format in version 1 the icon editor now supports a 5 color format (Frame, Header text, Header Back, Body Text, and Body Back). This is the standard frame that many programmers use.
    2: In version 2 the last 10 icon color sets are saved in a binary file and are recalled each time the editor is open. These color sets can then be selected and reused.
    Future Ideas and improvements:
    A graphics picker that would import a list of graphics to choose from
    Template creators were text zones could be created to avoid interfering with graphics.
    Incorporate some or all of the Ni editor functions.
    Text extractor that would fill in the text boxes from the icon image.
    Please feel free to give me feedback. This version has benefited greatly from ideas given to me by coworkers and other programmers.
    License:
    Creative Commons Attribution 2.5 License

    For anyone who is looking for a quick and easy text based vi icon editor I've posted my latest version in the LAVA CR
    http://forums.lavag.org/index.php?automodule=downloads&showfile=56
    File: Mark Balla Icon editor V2.2
    Author: Mark Balla
    [email protected]
    Description:
    This is the newest version of my vi icon editor and was created in LV8.2. The purpose is to help quickly create text base icons. The editor can be used in place of the standard NI icon editor or as a stand alone vi. see instructions. My original posting of the icon editor Ver. 1 can be found here
    LabVIEW 7.0,7.1 http://forums.lavag.org/index.php?s=&s...ost&p=19022
    LabVIEW 8.0 http://forums.lavag.org/index.php?s=&s...ost&p=12920
    Instructions:
    1: The icon editor was designed to be used as a replacement for the standard NI editor LV8.x only. To get LabVIEW 8.x to use the editor place the three files (lv_icon.vi, color templates.bin and the folder lv_icon_Subvis) in the LabVIEW 8.2\resource\plugins directory.
    The next time the icon editor is called LabVIEW will use the lv_icon.vi instead of the standard one.
    There is a button on the editor that will allow you to use NI's editor when a text icon is not desired.
    2: The icon editor can also be called from another vi or used as a stand alone tool. Make sure the "From Editor" control is set to false either via terminal in the lower left corner of the connector pane or manually in the FP. This setting indicates to the vi that a vi reference will be used to extract and save the icon information. If the "VI REF" input control is invalid at runtime a dialogue box will appear asking the user to select a vi.
    Version 2.1:
    Along with the auto drawing and Text compressing from version 1, version 2 has 2 new features.
    1: In addition to the 2 color format in version 1 the icon editor now supports a 5 color format (Frame, Header text, Header Back, Body Text, and Body Back). This is the standard frame that many programmers use.
    2: In version 2 the last 10 icon color sets are saved in a binary file and are recalled each time the editor is open. These color sets can then be selected and reused.
    Version 2.2:
    Along with the all the features from version 2.1, version 2.2 has several new features.
    1: A new color picker was added. The standard NI color picker has been replaced by one that will only show the legal 221 colors allowed by LabVIEW for icons.
    My thanks to Justin Goeres for the idea.
    2:Key navigation has improved. The key navigation will only set focus to the text boxes to navigate between boxes use the tab, enter, up and down keys.
    My thanks to boone_93 for the idea.
    3:Improved UI. The buttons and current and previous icons have been relocated for a more intuitive look. I have also added tip strips to the buttons and history array.
    My thanks to ahull for the idea.
    4:Random color picker. A random color button has been added to help pick colors.
    My thanks to Dave Graybeal for the idea.
    5: FP auto centers. The icon editor will now open in the center of the primary display.
    My thanks to tcplomp for the code.
    6: The ability to read the text in the icon was added. If the icon to be changed was previously created by this icon editor the program will automatically detect the characters in the icon and convert them back into strings. This function allows for small changes like color changes and spelling mistakes to be changed without having to type all the text over.
    This one was all mine.
    7:Bug with Panel close fixed. When the user presses the x in the upper right corner the editor will shut down gracefully instead of locking up.
    I made a avi file that shows some of the new features for Version 2.2 which I posted the support thread.
    Please feel free to give me feedback. This version has benefited greatly from ideas given to me by coworkers and other programmers.
    License:
    Creative Commons Attribution 2.5 License
    Attachments:
    picture of editor.png ‏47 KB

  • Question about layering text over an image

    Hi -- I am trying to place a layer of text over a ghosted image that I've imported into ID from Photoshop.  By "ghosted" I mean that the image has a layer of white fill over it that has been set at 50% opacity.  ID won't let text be layered on top of the imported image, no matter how many different ways I've tried to accomplish this.  It will allow another image to be layered on top, but not text.  If I place a text frame over the ghosted image and type even one letter, the red text overset warning icon appears.
    I tried applying the text in Photoshop and that works just fine until the file gets imported into ID, at which point the text looks terrible, having become somehow degraded in transit.  I am fairly new to ID and PS, and would appreciate any helpful input. 
    Thanks!
    ~Artemis

    Sounds like text wrap is applied to either the image or the frame above it, or both. Eihter turn it off if you don't need it for other reasons, or for the frame you want to use on top of it open the Text Frame Options and check the Ignore Text Wrap box in the lower left corner.

  • I have 4 mail icons on my desktop and cannot open any of them.  I have no idea how I have done this but want to go back to having one mail icon which opens.  What have I done and what should I do?

    I am new to mac pro and have managed to set up 4 mail icons on my desk top and none of them open mail.  What have I done and how do I get back to having just one in the doc which opens?

    HA! It turns out, that an app that I've never used before, became active during a time that I was multitasking and didn't realize it. I didn't notice the effects right away, because my main desktop has a special 3D desktop generator called, bumptop, which covers over any other desktop color or graphic in that area. So it wasn't until I swiped to go to a different desktop, that I noticed the random slideshow being displayed. All fixed now. What a relief.

  • How to write text over a picture in Pages 5.0?

    In a Pages 5.0 document I want to write a text over a picture. This text will allways stay 'behind' the picture.
    I can change the order of the picture (in front of at the back), but the text will not become visable.
    It did work in Pages '09...
    What am I doing wrong?
    For for helping me...

    Assuming your text is in your document, and you insert a picture. While the picture is selected, you will notice that on the right format panel, the Arrange tab has appeared. Select either Stay on Page, or Move with Text — depending on your image goal — and then look at the Text Wrap feature. By default, once you drop a picture into the document, it is set to Automatic. This means you can place your pointer in the image and just move it around, while text flows around it. The smaller the image the better the flow effect. This is a discussion about Pages v5.2.2, but it will work the same in v5.5.
    Let's say you want the image flush aligned to the left margin, but want text to flow above, to the right, and below the image. Change text wrap automatic to Around, select the right icon for Text Fit, and adjust your spacing up or down for the proximity of the text wrap to the image. It looks like this with Text Fit spacing set to 9 pt.

  • "Set text of container" behavior crashes Dreamweaver! (CS3)

    When I try to change pages which use the "Set text of
    container" behavior it
    crashes DW-CS3. The dialog which used to come up first shows
    a series of
    asterisks in the drop-down for the container selected, and
    the CPU does
    overtime for about a minute before the correct values appear.
    If I change
    any values and OK it, then CPU starts using over 90% on DW
    and nothing
    happens until I force a shut-down (I've left it running for
    over 15 mins!)
    I have tried setting up a new "Set text of container"
    behavior and the same
    thing happens.

    Oh it truly needs work...
    http://www.jackbooks.com/Wystan/Regional/Regionalism.htm
    Even on a simple new page with a couple of divs this
    behaviour is now very
    slow and the line of asterisks comes up while waiting for the
    dialog to
    load. What has changed? How can a simple behaviour be now so
    demanding?
    "Murray *ACE*" <[email protected]> wrote
    in message
    news:f4opvn$sod$[email protected]..
    > Can we see the page, please?
    >
    > --
    > Murray --- ICQ 71997575
    > Adobe Community Expert
    > (If you *MUST* email me, don't LAUGH when you do so!)
    > ==================
    >
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    > ==================
    >
    >
    > "Stephen C" <[email protected]>
    wrote in message
    > news:f4nd0t$8lq$[email protected]..
    >> When I try to change pages which use the "Set text
    of container" behavior
    >> it crashes DW-CS3. The dialog which used to come up
    first shows a series
    >> of asterisks in the drop-down for the container
    selected, and the CPU
    >> does overtime for about a minute before the correct
    values appear. If I
    >> change any values and OK it, then CPU starts using
    over 90% on DW and
    >> nothing happens until I force a shut-down (I've left
    it running for over
    >> 15 mins!)
    >>
    >> I have tried setting up a new "Set text of
    container" behavior and the
    >> same thing happens.
    >>
    >

  • 'set text of container' won't work in IE8

    (I'm resubmitting this discussion as I wrote the wrong version of IE in my last post).
    Hoping someone can help
    At the moment I am using 'swap image' to change the text that appears within one container when I hover over different buttons.
    I am using images of text rather than text itself because I have found that the 'set text of container' won't work when tested in IE8 (which is important for me). This makes the page much slower to load than it should be.
    It works perfectly in Firefox and Safari but not in IE8.
    Below is a link to my site page which shows how it should work (even though it's currently just images not text)
    http://www.lindengraphics.com.au/feedback.html
    And below is the coding which appears when I set the page using 'set text of container'.
    <div id="apDivthumb1"><img src="assets/client_feedback/fdb_thumb1.jpg" alt="thumnbail1" name="fdb_thumb1" width="43" height="43" id="fdb_thumb1" onmouseover="MM_setTextOfLayer('feedbacktbl','','&quot;Example of text I have written.&quot;')" /></div>
    <div id="apDivthumb2"><img src="assets/client_feedback/fdb_thumb2.jpg" alt="thumbnail2" width="43" height="43" onmouseover="MM_setTextOfLayer('feedbacktbl','','&quot;Example of text I have written.&quot;')" /></div>   etc etc
    I've taught myself Dreamweaver so am still fairly new to it and coding (although not new to website design) so please explain things in simple terms so that it's clear for me.
    If anyone has the time to help me with this it would be really appreciated!!
    Many thanks in advance, Michelle

    Good News!
    There is no problem in any version of IE on a windows based machine.

  • Setting image over the checkbox of JCheckBox

    hi everybody,
    I m new new to the forum so dont know about any rule but I am in trouble to setting image over the check box in JCheckBox(not side of the checkbox). I just want to cover the checkbox by some icon. I just wanna know is it possible? if ya how? it will be great help to me.
    thanks in advance for any kinda suggesion.

    Hi sudip;
    use JCheckBox(String text, Icon icon); to display icon instated of checkbox. and to differ checked & unchecked box use setSelectedIcon(Icon) on checkbox object to display some other icon whenever box is selected.

  • I need to add text over a still photo in iMovie.  Following directions that always worked before but not this time.

    I am running OS 10.6.8, an upgrade that I did after Christmas.  A couple of times a year, I need to make a video of my students' performances, and have always been able to add text over the still photos before, using the directions in iMovie "help."  However, this time, I am not able to choose a title style; no amount of clicking makes anything show up on the selected still photo.  And no amount of trying to choose the font style makes anything show up either.
    This is iMovie 09; is it possible that it is not compatible with my OS upgrade?
    I've been able to insert still photos into the video footage, but can't add any titles or acknowledgements.  Thank you so much for your help!  Since I only do this a couple of times a year, it always takes me forever to accomplish, which is why I printed off the Help directions to follow.

    just to make thing clear (sorry for sounding impudent!)
    you do .... :
    create a New Project
    make a selection of an Event and add it to the Project
    select a title and drag it onto the clip?
    iM does work with your OS ...

  • In Icloud I can't see my "numbers" icon which i need to select "tick" to transfer data to my other devices via icloud. any ideas why it's not showing up?

    In Icloud on my imac I can't see my "numbers" icon which i need to select "tick" to transfer data to my other devices via icloud. any ideas why it's not showing up?

    You have to do it app wise, which means that the icon won't show up in settings, but you will be able to move files from your local drive to iCloud via the Numbers app (move... > choose the iCloud option).
    It requires that you set up the same iCloud account on all your devices and that you have the latest version of Numbers on all your devices as well.

  • How to set up link on icon to forward PDF file as email attachment

    HI,
    I need urgent help.
    I know this used to work but cant find it in Acrobat XI.
    We created a file for a client, on the last page is a twitter, facebook and linkedIn icon which are set as links in Indesign to forward to the matching social network. Works fine when I created PDF with Hyperlinks.
    We also set up an envelope symbol which shall get, now where it is set up as PDF,  a link, so the PDF itself can get forwarded as a email attachment.
    I can not find this function on a MAC nor on PC Acrobat XI.
    Hope you can help, much appreciated!!!!
    THANKS

    Have a look at this thread:
    http://forums.adobe.com/thread/1275490?tstart=0
    where there is a script for submitting the PDF by email.

Maybe you are looking for

  • Aperture 3 and iPhone 4

    I imported my old iPhoto library into my new Aperture 3 library....when i try to sync my iPhone 4 with Aperture, I choose to sync the last 20 projects. It seemingly picks 20 random events, both from events/projects created in Aperture and events crea

  • Jobs for ABAP Certified Person

    Hi All, I am planning to do certification in ABAP through E- Learning from a authorized but not so popular institute , which I have doubt could help me out in placement . I am working in a big SAP End user company and giving support for functional mo

  • Turning on Match hides my iTunes in the Cloud purchases

    This is an odd one I've not seen anyone mention yet. I have enabled iTunes to show purchases in the Cloud so it displays my purchases in iTunes even if I haven't downloaded them. But when I turn on iTunes Match, not only does it just sit there "waiti

  • Best Headsets for SoftPhone

    What are the best sound quality headsets (monaural wired, USB, monaural wireless, USB, monaural wireless, Bluetooth)? I've tried some that sound ok, and some that sound just horrible. And some Bluetooth Plantronics devices are not even seen by the So

  • Application deployment and reporting does not work properly

    Hello I have a network and i management that with sccm 2012 cu2 Just have a problem with sccm Sccm dosenot show corect data for collection or reporting such as all windows sevens However self service portal doesnot work properly and for install progr