4 Replies Latest reply on Jun 13, 2007 5:40 AM by 843806

    ImageIcon Border

    843806
      Hi all,

      I'm looking to create a white rectangular border around my ImageIcon on a JLabel, not around the Jlabel. Any suggestions would be appreciated. Thanks.

      -roger
        • 1. Re: ImageIcon Border
          843806
          Here's something to get you started:
                    ImageIcon imageIcon = new ImageIcon(getClass().getResource("myIcon.gif"));
                    int borderWidth = 1;
                    int spaceAroundIcon = 2;
                    Color borderColor = Color.WHITE;
          
                    BufferedImage bi = new BufferedImage(imageIcon.getIconWidth() + (2 * borderWidth + 2 * spaceAroundIcon),
                              imageIcon.getIconHeight() + (2 * borderWidth + 2 * spaceAroundIcon), BufferedImage.TYPE_INT_ARGB);
          
                    Graphics2D g = bi.createGraphics();
                    g.setColor(borderColor);
                    g.drawImage(imageIcon.getImage(), borderWidth + spaceAroundIcon, borderWidth + spaceAroundIcon, null);
                    g.drawRect(0, 0, bi.getWidth() - 1, bi.getHeight() - 1);
                    g.dispose();
                    
                    JLabel label = new JLabel("MyText", new ImageIcon(bi), JLabel.LEFT);
          • 2. Re: ImageIcon Border
            843806
            Hey - did my answer help you, what about the dukes?
            • 3. Re: ImageIcon Border
              843806
              lol
              • 4. Re: ImageIcon Border
                843806
                Yeah, I guess Its kinda funny... Here I use some time to answer someone and they don't even bother replying..