Add a border to AWT Label

I had create a swing JLabel and used the JComponent setBorder() method to create a border. I need to not use swing and stick to AWT. Is there a way I can set the same border on an AWT component?
Thanks,
Chris

I think I screwed something up. The System.out... statements below print all 0's. So
getBounds() is not getting the size of the Label?
     * Initialization method. Executed when Applet is loaded
     public void init() {
          Color backGround = new Color(255, 255, 255);
          Color foreGround = new Color(0, 0, 0);
          // Process our Applet Parameters
          // Only if we don't have them
          if(bgColor == null || fgColor == null) {
               bgColor = getParameter("bgColor");
               fgColor = getParameter("fgColor");
          if(bgColor != null) {
               int hex;
               hex = stringToHex(bgColor);
               backGround = hextToColor(hex);
          if(fgColor != null) {
               int hex;
               hex = stringToHex(fgColor);
               foreGround = hextToColor(hex);
clockText.setFont(theFont);
clockText.setText("00:00:00pm");
          // Set our colors
          clockText.setForeground(foreGround);
          clockText.setBackground(backGround);
setLayout(new FlowLayout());
add(clockText);
Dimension dim = clockText.getSize();
Rectangle rect = new Rectangle((int)dim.getWidth(),
(int)dim.getHeight());
System.out.println(rect.x);
System.out.println(rect.y);
System.out.println(rect.width);
System.out.println(rect.height);
Graphics g=getGraphics();
g.setColor(Color.black);
g.drawRect(rect.x-1,rect.y-1,
rect.width+2,rect.height+2);

Similar Messages

  • Add a border around an AWT Label

    I need to add a border around an AWT label like I would for a Swing Label. I do not have BorderFactory available in AWT. Is there an easy way to do this?
    Thanks,
    Chris

    Bump

  • How to add a Border around an ImageView

    Hi all,
    I'm adding a row of photos in my application which are being resized to fit into some constrained space with Preserve Ratio true. They are put in a TilePane, with a Label below each photo.
    Basically, I give all my ImageViews a fitHeight of 120 pixels, and let them determine how wide they will become themselves in order to preserve the ratio.
    It looks great.
    However, I would like to add a Border around these images, as they sometimes fade too much into the background to clearly see the edges. ImageViews themselves donot support borders, so I'm forced to wrap these ImageViews inside another container.... but, no matter what container I use, the container itself refuses to resize itself to fit exactly around the image -- it seems to be completely oblivious of the real size of the Image -- with some parameters the ImageView will simply render itself outside the edges of its container, and with other parameters the container is wider than the ImageView leaving a gap on the right side.
    This is yet another instance where I want my ImageViews to resize themselves to fit the available space, resulting in a huge struggle to force these components into their proper straight-jacket. Anyone got any solutions for this?

    I'm afraid that also won't work, as the Image needs to be scaled, and the dimensions you are using are from the unscaled image.
    I've however am now using this class to get what I want, together with a stylesheet to specify the border it works and I get nice borders.
    package hs.mediasystem.util;
    import javafx.beans.property.BooleanProperty;
    import javafx.beans.property.ObjectProperty;
    import javafx.beans.property.SimpleObjectProperty;
    import javafx.geometry.Bounds;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.Node;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.Region;
    import javafx.scene.layout.StackPane;
    public class ScaledImageView extends Region {
      private final ImageView imageView = new ImageView();
      private final StackPane effectRegion = new StackPane();
      private final ObjectProperty<Pos> alignment = new SimpleObjectProperty<>(Pos.TOP_LEFT);
      public ObjectProperty<Pos> alignmentProperty() { return alignment; }
      public final Pos getAlignment() { return this.alignment.get(); }
      public final void setAlignment(Pos pos) { this.alignment.set(pos); }
      public ScaledImageView(Node placeHolder) {
        getChildren().add(imageView);
        getChildren().add(effectRegion);
        getStyleClass().add("scaled-image-view");
        effectRegion.getStyleClass().add("image-view");
        if(placeHolder != null) {
          effectRegion.getChildren().add(placeHolder);
          placeHolder.getStyleClass().add("place-holder");
          placeHolder.visibleProperty().bind(imageView.imageProperty().isNull());
      public ScaledImageView() {
        this(null);
      @Override
      protected void layoutChildren() {
        Insets insets = effectRegion.getInsets();
        double insetsWidth = insets.getLeft() + insets.getRight();
        double insetsHeight = insets.getTop() + insets.getBottom();
        imageView.setFitWidth(getWidth() - insetsWidth);
        imageView.setFitHeight(getHeight() - insetsHeight);
        layoutInArea(imageView, insets.getLeft(), insets.getTop(), getWidth() - insetsWidth, getHeight() - insetsHeight, 0, alignment.get().getHpos(), alignment.get().getVpos());
        Bounds bounds = imageView.getLayoutBounds();
        effectRegion.setMinWidth(bounds.getWidth() + insetsWidth);
        effectRegion.setMinHeight(bounds.getHeight() + insetsHeight);
        effectRegion.setMaxWidth(bounds.getWidth() + insetsWidth);
        effectRegion.setMaxHeight(bounds.getHeight() + insetsHeight);
        layoutInArea(effectRegion,  0, 0, getWidth(), getHeight(), 0, alignment.get().getHpos(), alignment.get().getVpos());
      @Override
      protected double computePrefWidth(double height) {
        return 0;
      @Override
      protected double computePrefHeight(double width) {
        return 0;
      public final ObjectProperty<Image> imageProperty() { return imageView.imageProperty(); }
      public final Image getImage() { return imageView.getImage(); }
      public final void setImage(Image image) { imageView.setImage(image); }
      public final BooleanProperty preserveRatioProperty() { return imageView.preserveRatioProperty(); }
      public final boolean isPreserveRatio() { return imageView.isPreserveRatio(); }
      public final void setPreserveRatio(boolean preserveRatio) { imageView.setPreserveRatio(preserveRatio); }
      public final BooleanProperty smoothProperty() { return imageView.smoothProperty(); }
      public final boolean isSmooth() { return imageView.isSmooth(); }
      public final void setSmooth(boolean smooth) { imageView.setSmooth(smooth); }
    }

  • Anyone know how to add a border to buttons in JOptionPanes?

    I can't find a way to add a border to the buttons on my JOption dialog boxes. I would like them to have the same look and feel of my other buttons. Any suggestions?

    This inspired me to look for a way to globally change the background color of JTextFields. ALso the color of JLabels and the font for labels and textfields. I searched the API for topics related to javax.swing.UIManager.put but cannot find anything helpful. Can you point me in the right direction or tell me how to do this?
    Thanks

  • How can I see the border of a label

    I'm wondering how can I see the border of a label.
    I'm trying using the following command but is giving me an error that cannot resolve symbol setBorder. There is another way to do this?
    label_01.setBorder(BorderFactory.createLineBorder(Color.black));

    the awt Label class doesn't have a setBorder method, you need to use a JLabel
    asjf

  • Border around a label

    I am trying to create a black border around a label using awt. Is there any way to do this? I have been trying to do it by creating two labels, one black and one white, with the black one slightly larger and putting the white one on the same cell (am using GridBagLayout) as the black one, but that doesn't work, only the black one is visible.
    Perhaps there is a different approach that someone knows about?
    Thanks for any assistance!

    I suggest using swing instead of awt, and then use the JComponent.setBorder method. You can find the types of borders you can create in javax.swing.border package. You can also use the BorderFactory class to create these borders for you.
    The problem with trying to put two items in the same position in the gridbag layout is that the gridbag layout (can) resize the components to fill the space, for one, so it might be resizing both components to the same size. Also, there is not concept of a z-index, so there is no guarantee which one will be painted first.
    - Adam

  • How to add a border around images posted to Facebook?

    I am using LR 4.1, also usis PS CS5.
    Anyone who uses Facebook to showcase image galleries knows that Facebook changes how images are displayed from time to time.  One month it will be on a black background and the next on a white background.  And then they put overlay's on top of your images and they change things around whenever they wish.  There is not rock solid consistency from Facebook on how they display your images across devices or over time.
    What I am trying to do is to add some consistency to how my images are displayed by adding my own border to my images.  I need some ideas on how to best do this.  The way that I have been doing it does not appear to be ideal and I think someone must have a better way.
    Ideally, I would want Lightroom to add a border for me based on some setting under the export manager.  But as far I know there is no setting to do this?  (Why doesn't lightroom have any border options anywhere yet for anything it exports?  This would be relatively simple I think.)
    Here is the only way I know how to solve my issue.
    First, my other considerations:
    I want to keep my original images in my catalog in tact and as is w/o a border and with layers if it is a .psd file.  I do NOT want to destructively add a border to the catalog images, only the images that end up on Facebook.  I also want to add my watermark image to the final image so that it is done as the last step so that the bottom part of my watermark shows my web site address over the white border on the bottom of the image.  Using a droplet and the watermark in the same step does not work properly because it applies the watermark before it runs the action, not after.
    I have created an action to add a x pixel white border by:
    Merging (flatten) all layers
    Creating a new unlocked background "image" layer
    Expanding the canvas by x pixels.
    Creating a new white filled layer and moving it to the bottom of the layer's pallet.
    Adding a 2 pixel black inside stroke to my image layer and adding a drop shadow.
    I created a droplet from this action and put it in the droplet folder for LR.
    Now for the repeated steps that I am going through...
    Select the images that I want to write to Facebook.
    Export these images to a new folder using the droplet.
    Import the folder of all of these images back into Lightroom.
    Move the new images with borders on them into the correct LR FB publish service.
    Publish the photos using the sharpening and watermark settings.
    Delete the .psd files created in Step #2
    The steps that I would like to avoid are #2, #3, #6
    Or maybe I am going about this all wrong?  Anybody have any better ideas?

    You may find it much easier to use the Migrify plug-in from Tim Armes/Photographers Toolbox which does what you want from within Lr.

  • I am making a graduation video for my cousin using Final Cut Pro. I have photos layered over videos, and I was wanted to find out how you can add a border around the photos so they stand off of the video. Anyone know what I could do?

    I am making a graduation video for my cousin using Final Cut Pro. I have photos layered over videos, and I was wanted to find out how you can add a border around the photos so they stand off of the video. Anyone know what I could do?

    You would need an image editor to edit the images and add a border to the image first before importing them into Final Cut.
    Cheapest and very good image editor?
    PIxelmator.
    Located in the Mac App Store. $14.99 USD.
    Here is the Pixelmator website to give you an overview of the app.
    http://www.pixelmator.com/
    Good Luck!

  • How to add a border to image

    I am a newby to Photoshop.  All I want to do is add a
    border to my image.  Can't find a tutorial. Help?

    Thank you. It looks very helpful.
    Date: Mon, 27 Jun 2011 15:03:52 -0600
    From: [email protected]
    To: [email protected]
    Subject: How to add a border to image
    Here's a little video from Adobe TV that shows you how to create borders in Photoshop Elements. If you don't have Photoshop Elements, skip the first 1:25 of the video, the rest of the steps apply to Photoshop as well:
    http://tv.adobe.com/watch/learn-photoshop-elements-9/creating-a-photo-borde/
    >

  • How to add a border to ListView

    I want to add a border to a ListView control. Using the WS_BORDER window style has worked:
    HWND hListView = CreateWindowEx(0, WC_LISTVIEW, "", WS_CHILD | LVS_REPORT | WS_VISIBLE | WS_BORDER, 10, 10, 320, 200, hWnd, 0, hInstance, NULL);
    But I am not sure if this is how it is done, maybe I am missing some other style or I should use a style specific to ListView (i.e. LVS_xxx) or something.
    So is WS_BORDER sufficient?

    WS_BORDER should be fine, and is generally the best bet for a standard window that supports it.

  • How to add a border without a soft edge?

    I want to add a border to a graphic but I don't want a soft edge. Anyone know how to do that? I'm using Elements 5.0
    Thanks.

    Karla,
    A simple hard edged border can be created by increasing the canvas size and
    filling the added area with a color. Go >Image >Resize >Canvas Size and
    fill in Width and Height. Next select the added space and fill it with the
    color (>Edit >Fill Selection). There are more sophisticated ways to it, but
    this will get you on the way. If you use >Select >Modify >Border, you only
    get a soft edge.
    Juergen

  • How to add a Border

    Hi!
    I want to know how to add a border to a particular column (Vertical) in the report. I have no clue, please help me.
    Thank you very much.
    null

    A partial solution:
    -- Select a border color, as suggested.
    -- Pull down Format/Border, and deselect
    the "top" and "bottom" buttons.
    This will get you vertical lines around all
    cells with data, but not cells with null
    values. Also (it's been a while since I
    looked at this in detail) this works nicely
    from the live previewer but doesn't work in
    all output formats - not HTML for instance,
    if I recall correctly. Depends on which
    type of output you need.
    If you have a lot of null cells, i.e. with
    no border, the lines is your best option.
    Done neatly it looks about the same.
    HTH.
    -- Allan Plumb

  • How to add a border for Panel (jdk 1.1) ?

    how to add a border for Panel (jdk 1.1) ?

    Border's are a Swing feature, you will have to draw one by yourself (extend Panel and override paint()).

  • How to add a border to an entire Pages document?

    I can't seem to find, anywhere, the option to add a nice looking border to my wedding maps. What's up?

    Peter;
    I've been trying to put a border on a text box with no luck. In Inspector I select Text>Borders and Rules then I hit the 'add a border around the paragraph' button. All I get is a line above the paragraph, though if I then make the box big I do see a line below the paragraph but no side lines... at all. When I try with a shape box I have no problem putting a line/border around the box.
    Karen

  • Add a border around a Picture in picture???

    I am building a montage of images over other video and I want to add a border to the images. I tried every filter I can think of in cs3 but the best I find is "Alpha Glow" and that looks bad.
    Any ideas...am I blind or just stupid?
    Thanks,
    Mark

    Welcome to the forums.
    Have a look at: FAQ:How do I add a border to a clip?
    Cheers
    Eddie

Maybe you are looking for

  • Is There a Limit to How Many Buttons in a PDF?

    Good afternoon. Forgive me if this is answered somewhere else, but I couldn't find anything with the search tool; does anyone else think this site is a little primitive? I have a JavaScript file that takes ~150 separate PDF files and combines them in

  • Group by 10 minutes

    Hi all, Oracle 11 g I have the following table and data CREATE TABLE dummy_data ( ID number NOT NULL ,test_Timestamp timestamp NOT NULL insert into dummy_data (id,test_TimeStamp) values (1,'08-MAR-10 09.43.30.922000000'); insert into dummy_data (id,t

  • Antlr.TokenStreamIOException when access jsp

              i'm starting weblogic 6.1 in rh9.0, and get this error. the problem is we have           a couple instances of weblogic, not all of them have this problem.           weblogic.utils.ParsingException: nested TokenStreamException: antlr.TokenS

  • Mustak Scan Express A3

    After failing to get my dell scanner working I thought I would hook up my A3 scanner to see if I have any joy here. Firstly I installed parallels Then windows XP. I loaded the supplied software from Mustak onto windows & followed instructions & as re

  • How do I move an iMovie from my library to theater?

    Hi, I was creating an i Movie on my iMac, and I wanted to edit it from my iPhone 4s. My iMac is running OS X Mavericks, and my Iphone is iOS 7. I heard if you put it inot iMovie theater, the movie is accesible to all of you iCloud devices. So I was w