Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By jim829
  • 1 Post By camickr

Thread: Rounded image

  1. #1
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Rounded image

    Hello guys,

    I'am trying to make an welcome logo when I start my program. The problem is that I want to show only the image that I made (the image have rounded corners), and the result is this:

    Rounded image-1bul.png

    The code is:

    Java Code:
    public class Welcome extends JFrame {
    
    	private ImageIcon pic = new ImageIcon(getClass().getResource("intro2.png"));
    	private Dimension picsize = new Dimension(pic.getIconWidth(), pic.getIconHeight());
    	
    	public Welcome(){
    		setUP();
    		setDesign();
    		setVisible(true);
    	}
    
    	private void setUP(){
    		setSize(picsize);
    		setLocationRelativeTo(null);
    		setUndecorated(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
    
    	private void setDesign(){
    		//		setShape(new RoundRectangle2D.Double(0, 0, 300	,300, 50	, 50));
    		JLabel label = new JLabel(pic);
    		label.setOpaque(true);
    		add(label);
    	}
    As you can see, I tryed to use setShape, but I can't make the perfect match with the picture. Is any other solution?

    Thanks

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Rounded image

    The problem is with your image. You need to use an image that has transparent pixels on the outside of the rounded corners. Then the label will just paint the image normally as there is no need for custom code.

  3. #3
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Rounded image

    Hi camickr,

    And I made that! I used a .png image with transparent corners

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,524
    Rep Power
    5

    Default Re: Rounded image

    Can you provide your image? But first, try setting your label's opaqueness to false.

    Regards,
    Jim
    Last edited by jim829; 02-13-2014 at 07:11 PM.
    camickr likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Rounded image

    But first, try setting your label's opaqueness to false.
    Good catch, I missed that line of code.

  6. #6
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Rounded image

    Hi guys,

    still doesn't work with the false flag on setOpaque. Here is the image:

    Rounded image-temp99.png

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Rounded image

    You need to make the frame transparent:

    Java Code:
            setUndecorated(true);
            setBackground( new Color(0, 0, 0, 0) );
    jim829 likes this.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,524
    Rep Power
    5

    Default Re: Rounded image

    Yep. Funny, I thought his desktop was actually an image in a larger Frame. Couldn't understand why it wasn't working for him. Also, as long as the OP is doing an undecorated JFrame, he may as well use a JWindow instead.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Stored procedure OUT parameter is rounded
    By diamonddragon in forum JDBC
    Replies: 0
    Last Post: 02-10-2012, 09:03 PM
  2. data of more than 7 digits is rounded up by 1
    By shihad_s in forum New To Java
    Replies: 4
    Last Post: 05-10-2011, 12:31 PM
  3. Rounded Rectangle
    By Arnold in forum Android
    Replies: 0
    Last Post: 05-27-2010, 04:06 PM
  4. Rectangle with rounded edges??
    By orchid in forum Java 2D
    Replies: 1
    Last Post: 05-10-2007, 02:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •