Text on top of an image in a component

How do I get text on top of an image in a component?
ImageIcon icon = new ImageIcon("foo.jpg");
JLabel label = new JLabel();
label.setIcon(icon);
// this prints next to, not on top of, the image
label.setText("Hello"); if I add this:
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setVerticalAlignment(SwingConstants.CENTER);The text doesn't appear at all. I assume it is "underneath" the image.
null

if I add this:
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setVerticalAlignment(SwingConstants.CENTER);The alignment methods determine the position of the component in the parent container, if the layout manager respects those values.
I believe you want:
JLabel label = new JLabel("Some Centered Text");
label.setIcon( new ImageIcon("???.jpg") );
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.CENTER);

Similar Messages

  • HTML text on top of productBranding image

    Hi all,
    I'm new to using UIX XML in JDeveloper 10g and was wondering how I could render HTML text on top of an image (i.e. the text is not part of the image.gif). I'm able to display text all around the image but not on top of it. I'm guessing that this can be done since it is one of the BLAF specifications for the Product Branding guides.
    Having spent a couple of days looking through various related posts, I've yet to make any head way.
    Cheers

    Woohoo! Got it. Could have done it in the stylesheet as well!
    <rowLayout>
    <contents>
    <cellFormat height="70" width="300">
    <inlineStyle>
    <property name="background-image">url(images/financial_collage.gif)
    </property>
    </inlineStyle>
    <contents>
    <styledText text="Product Information">
    <inlineStyle>
    <property name="font">Garamond
    </property>
    <property name="font-size">+24
    </property>
    <property name="color">#336699
    </property>
    </inlineStyle>
    </styledText>
    </contents>
    </cellFormat>
    </contents>
    </rowLayout>

  • How can I have text on top of an image?

    say i want to do something like this for my site:
    http://www.whspconsumercare.com/images/RxDesign.jpg
    what would be the best way to have those colored rounded
    boxes in the background, and be able to type or place an image over
    it? I tried having it as the background image, and putting the text
    in a <div>, but this way the text is not always positioned
    properly depending on how large the browser window is, etc.
    any suggestions?

    quote:
    Originally posted by:
    Newsgroup User
    http://www.html.it/articoli/niftycube/index.html
    ATTN Alan Smithee (or anyone else who has used the Nifty
    Corners site above or just knows a lot about CSS/html) -
    I have still not been able to figure out the problems I'm
    having with my rounded boxes:
    http://www.whsprx.com/indexRcorners.html
    mostly, you'll see the orange box on top is messed up right
    below the image. I'm not sure why, because the other boxes that
    have images look fine. Help please?
    (let me know if there's any additional info I can provide
    that might help)

  • How do I insert text on top of an image

    I've got my masthead at the top of my page, and now I want to add text - log in / join / subscribe - which will be links that change based on the user's state (ie, log in switches to log out). How do I insert this text over the image in Dreamweaver cs4?
    Help much appreciated!!!
    Thanks!

    If you use the image as a background image on the masthead via your stylesheet, you can then place whatever you want over the top of it.
    References:
    http://reference.sitepoint.com/css/background-image
    http://www.w3schools.com/css/pr_background-image.asp
    Nadia
    Adobe® Community Expert : Dreamweaver
    Unique CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    Book: Ultimate CSS Reference
    http://www.sitepoint.com/launch/005dfd4/3/133
    http://twitter.com/nadiap

  • How to epub text on top of images.

    I am trying to epub a children's book. I have an basic color and then I bring the image on the page but indented. Then I put the text on top of the image.
    I have tried articles and I can't get the text to go ontop of the image. how do I do that. The images are jpegs. I tried png and psd.  I tried putting the text on the image in photoshop but when I brought it over to indesign, the text looked terrible.
    thanks

    Text and image would have to be rasterized together, either in Photoshop or in InDesign in EPUB. There is no concept of layering in an EPUB file.
    I don't think even fixed layout EPUBs support layering.

  • How do I make text sit on top of an image without it disappearing.

    I am currently copying and pasting images with captions from quark express files to indesign cs6 files.
    Everytime I copy and paste these images the captions which are on top of the image disappear behind
    the image.  How do I put the text back on top of the image?  and in general how do you put text on top
    of an image without it disappearing?

    text.on.image.question wrote:
    I am currently copying and pasting images with captions from quark express files to indesign cs6 files.
    This is probably a really bad workflow that will end up biting you. I've not actually been able to copy a an image box from Quark and paste it into ID to test, so I don't know waht youare doing, exactly, but odds are you are not pasting a link to the image (doe sit show a link in ID's Links panel?). If not, you should be building this from scratch or opening the Quark file directly in ID (up to version 4 with out a plugin, later than that requires the Q2ID plugin from Markzware).

  • How to I add text on top of image? I am using pages version 5.2.2

    I am working on an apple desk top OSX version 10.9.4. Since the new pages version 5.2.2 came out, I have been unable to add text on top of an image. Can anyone help me? Thanks ahead of time.

    Pages v5 is not as flexible as Pages ’09 v4.3. If you want text over a free-standing image in your document, then you will need to place it in a Text Box, Shape, or other custom container created with the Unite, Intersect, Subtract, or Exclude items in the Arrange panel. Simply selecting the image and then, in the Arrange tab, stating move with text; setting wrap to none, and clicking back/ward — does not help.
    You will need one of the containers from the second sentence positioned on top of your image. Once your text is input and styled, select the Text Box and the image, then from the Arrange tab, select group to maintain your text/image spatial relationship. If you need the image and its text container to adapt to other text in your document, you can enable the wrap functionality that best suits your document goals.
    This can get interesting, because you can independently define the selected Text Box content as a text placeholder, and the image as a media placeholder. Save it as a template. When you open a new document with this template, you can drag and drop a new image onto the old one, and it is automatically scaled and replaced without effecting the Text Box content. You can then double-click the Text Box content and change it.

  • Adding slide in caption on top of main image in gallery

    ok, now the same caption question from another angle...how
    would you get the caption to display on top of the main photo...and
    once that is accomplished, I want to add a slide effect *smile*
    I found a page that I want to recreate with spry...but its
    gonna be hard...I have the basics started, but cannot figure out
    how to put the text on TOP of the image
    http://www.nmdhsem.org/default.asp?CustComKey=270308&CategoryKey=274276&pn=Page&DomName=nm dhsem.org
    oh I am using the photo gallery demo, but hiding the select
    and gallery name so that just 3 images cycle on opening the page
    Edited: 08/28/2007 at 03:06:40 PM by karonz

    ok, so far I have this...I got the images to fade, but still
    would like to have a caption that fades in and out as well...
    any suggestions
    http://www.nmprc.state.nm.us/Copyindex.htm
    oh...and lol...I still have to get some images from NM
    instead of china *g*

  • Adding Text to a pre-defined Image

    I have an Image that is within a JInternalFrame and I am wanting to add text on top of the Image. I have tried using the getGraphics().drawString() method, however this requires that the image in question have been created with the create(w,h) constructor, where as my image is created using an MemoryImageSource.
    Does anyone have any ideas as to how I could add text to a predefined Image? Perhaps using some sort of transparent Pane/Panel may work?
    Cheers
    J

    Here's the code I used to solve my problem, for those that may be interested.
    BufferedImage bf = new BufferedImage(imageWidth,imageHeight,
    BufferedImage.TYPE_3BYTE_BGR);
    G = bf.createGraphics();
    G.drawImage(getImage(),0,0,null);     //Get the original Image
    G.setColor(Color.red);
    //Draw a rectangle surrounding the object
    G.drawRect((od.getBBLeft()-1),(od.getBBTop()-1),
    (od.getObjectWidth()+2),(od.getObjectHeight()+2));
    //Add the object text to the image
    G.drawString(text,(od.getBBLeft()-1),(od.getBBBottom()+20));
    getPixels(bf);      
    image.flush();     //Clear the presently displayed images chache
    setImage(bf);     //Define the new image for the JInternalFrame
    repaint();     //Call the repaint methods for this JInternalFrame
    Cheers
    J

  • Exporting Text out of Fireworks on top of BG image

    In Fireworks I have a black background with text content on top of it.  I would like to export both so that the bg comes into dreamweaver as a background image and the text comes in as editable text.  Right now when I slice the bg it automatically includes the text in the image.  How do I export text that is on top of an image?

    I forgot earlier to say that you must finally export as CSS and Images.
    I'll try to give some simple advice while trying to export css from Fireworks CS4.
    You can apply the blue background, by simply adding it from the CSS and Images export options. You should not draw it in your document(, it doesn't matter at all).
    Draw Rectangles all over your document to finally export them as div tags.
    When you need to apply a background, think of what exactly you want your background to be, solid color, or a picture?
    If it's going to be a picture, you must place that picture and insert a slice to it, set as background.
    If you want color, you don't put a slice. You just ...draw a rectangle. Write some text over the rectangle, and you can export it as CSS.
    A slice is used to export images. Otherwise, you just draw rectangles to export the current color as a value in your exported CSS.
    The black background color of your document, can be set as a color value inside your exported css, so you don't have to place a slice for that.
    Watch not to overlap objects like images, rectangles and slices. It is going to be hard to achieve an excellent result in order to construct your web site with Fireworks while trying to export CSS.
    Jim has already said it Fireworks won't help you that much with coding like hand coding or Dreamweaver will.

  • How to get the text to appear on top of the image

    I am using the following piece of code to add a label to a JPanel -
    JLabel label = new JLabel();
            label.setIcon(new ImageIcon("object.gif"));
            label.setText("An object");
            label.setBounds(xCoordinate, yCoordinate, width, height);
            display.setLayout(null);
            display.add(label);The problem is that the image is being placed over the text so I cannot see the text, does anyone know how I can fix this?
    Thanks.

    Try setIconTextGap in JLabel. Or, maybe your bounds
    are too small.
    JLabel also has a constructor that takes both the
    icon and the text at the same time.I know my bounds are large enough because if I comment out the add image then I can see the text and there is enough room for it.
    I don't think setIconTextGap can help me because that will just move the position of the text in relation to the image but I would like it to be directly on top of the image.
    I tried the constructor but that is causing a java.lang.reflect.InvokationTargetException which is fairly strange because the method that im working on does not use reflection or change anything in the method which does.

  • Entering text on top of Image

    Hi
    I'm trying to come up with idea how to enter text on top of the existing image at known position. Or simple saying to add TextField component on Graphics2D so I can type text in it.
    If anybody have done this please help
    Thanks

    Hi
    I'm trying to come up with idea how to enter text on
    top of the existing image at known position. Or simple
    saying to add TextField component on Graphics2D so I
    can type text in it.
    If anybody have done this please help
    ThanksHad the same problem - when I tried to overlay a TextField on top of my graphic the graphic repainted itself over the TextField. The (easier) solution was to put the image on its own JComponent within the JPanel I was writing too. This way the TextField could be made visible or invisible and laid on top of the image. More involved solutions would mean creating your own text editor on top of the graphic - this is covered in one of the Java tutorials, but you have to manage the details.

  • How can I add callouts on top of anchored images in CS6?

    I am using InDesign CS6 on a MacBook. I have multiple anchored images in a long document. Some of the images require callouts, such as labels or arrows, which should display on top of the image and should always stay with the image as if these items were also anchored. Is there a way to layer images in InDesign so that they are all anchored?
    I tried grouping the callout objects with the anchored object, but you cannot select an anchored object and other objects at the same time. I know in Word you can create an image canvas and add multiple items to that, and they are all grouped together. Is there a way to do that in InDesign? Or would I have to anchor each callout along with its corresponding image?

    Peter, your advice was very helpful. However, the text boxes (callout labels) that are included in the grouped objects get distorted once the grouped objects are anchored. Each text box shows the red +. When I expand the text box to fit content, the text box expands vertically so that all of the text is below the originally anchored object.
    The other callouts (just lines) stay in place perfectly.  Any insight into why the text boxes don't behave the same way that the lines do?

  • Text on top of Pics or Pics behind Text

    Does anyone know how I can have my picture behind my Text in Pages 09. I know the generic way is to print the picture and reinsert the paper back into the printer and let the text print on top of it. This would suck. I have a picture that I have Faded which covers the whole page. I want to Type on top of this picture. This will have a nice affect. While reading the info on the page you can slightly see on the invitation what the event is about. Please help me figure out how to get the cursor on top of the pic so as to add text on top of it.
    Thanks

    Select the image by command clicking on it:
    +Menu > Arrange > Send to Back+
    Create a textbox from the Toolbar at the top of your document window, with the text in it and position it over the image.
    You can fade the text if you wish using:
    +Inspector > Graphic > Opacity+
    Download the Pages09_UserGuide.pdf from under the Help menu and familiarise yourself with how Pages works. This is not dissimilar from almost any other program
    Peter

  • Putting text on top of a custom shape

    If I put text on top of a custom shape I've added, the text doesn't show.   I know it's there because if I change the opacity of the "shape" I can see the text is in fact there.   How do I force the text to be on top of the customer shape?   I'm using the shape as a "thought bubble" so one would think this is a common thing to do.

    It's probably not because of the shape. First of all check your color square to be sure the text isn't the same color as the shape. Also, you may  need to make text very much larger in PSE than you normally would, because text size is dependent on the resolution of the image. A high resolution image can need really big text before you can easily see it. Don't be afraid to type in a much larger number than is available in the pulldown menu.

Maybe you are looking for