Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
Like Tree1Likes

Thread: How to add an ImageIcon on a JPanel???

  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How to add an ImageIcon on a JPanel???

    Quote Originally Posted by Angelo View Post
    so basically you
    1. defined the playerAvatar as a JLabel;
    2. did not set the panel layout as null, so you used the flowlayout;
    I would use whatever layout works best for the situation. In my code, I used the JPanel layout default, which you are correct, is FlowLayout.

    so I can not use a generic JComponent, but I have to define the avatar as a JLabel right?
    You can use a JCompnent, but if all you're doing with it is showing the image, a JLabel does this much more simply and easily. If you use a JComponent, you'd have to also override getPreferredSize and have it return the size of the image. You might also would need to override getSize if you use null layout.

    why if I set the layout = null the image does not appear?
    If you have a container use null layout, then you the coder are directly responsible for specifying the container's components' sizes and locations. I would only use this layout if I wanted to have the user manually drag a component around or if I wanted to animate the motion of a component.

  2. #22
    Angelo is offline Member
    Join Date
    Dec 2011
    Posts
    24
    Rep Power
    0

    Default Re: How to add an ImageIcon on a JPanel???

    Anyway thank you so much!!!

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How to add an ImageIcon on a JPanel???

    You're quite welcome!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. JFrame+JPanel+JButton+JtextArea+ImageIcon
    By zusss in forum AWT / Swing
    Replies: 11
    Last Post: 02-18-2011, 10:40 AM
  2. Need help with ImageIcon and int
    By proceeded in forum New To Java
    Replies: 9
    Last Post: 01-23-2011, 10:10 PM
  3. ImageIcon HELP!
    By ben1989 in forum New To Java
    Replies: 1
    Last Post: 05-05-2010, 08:48 PM
  4. send imageIcon over RMI
    By nadia in forum Advanced Java
    Replies: 4
    Last Post: 01-06-2009, 03:41 PM
  5. ImageIcon and size
    By wokena in forum Java 2D
    Replies: 3
    Last Post: 12-21-2008, 08:47 AM

Tags for this Thread

Posting Permissions

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