Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: JLabel, multiple images?

  1. #1
    Member
    Join Date
    Jul 2013
    Location
    Baltimore, MD
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default JLabel, multiple images?

    Is there any way to put more than one image on a JLabel?

    If not JLabel, what's the best way to put multiple images?

    I'm trying to make a card game, that's the reason.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: JLabel, multiple images?

    Create a single image by creating a BufferedImage and drawing each image onto that BI and then use the BI in the JLabel.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    tonynsx (November 24th, 2013)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JLabel, multiple images?

    Or, if you can use standard playing cards (and maybe some not standard) there are open source card back and front images available on the Internet for your use. If you're building your own special cards, I suggest you build and save the card images in advance. Building them on the fly is unnecessary overhead.

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    tonynsx (November 24th, 2013)

  6. #4
    Member
    Join Date
    Jul 2013
    Location
    Baltimore, MD
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Re: JLabel, multiple images?

    I'll look at the BufferedImage option, I don't know anything about it, so I'll look on YouTube etc.

    I already have the 52 cards images available

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: JLabel, multiple images?

    Why are you using a JLabel for displaying images? Why not use a custom JPanel with its own paintComponent() method that draws as many images as you want?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #6
    Member
    Join Date
    Jul 2013
    Location
    Baltimore, MD
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Re: JLabel, multiple images?

    Quote Originally Posted by Norm View Post
    Why are you using a JLabel for displaying images? Why not use a custom JPanel with its own paintComponent() method that draws as many images as you want?
    Just because that's the only way I've been displaying images in the past programs. I'll look at the paintComponent() also.

Similar Threads

  1. Replies: 7
    Last Post: November 4th, 2013, 03:07 AM
  2. [SOLVED] Using multiple timers to draw images??
    By athrun8703 in forum AWT / Java Swing
    Replies: 21
    Last Post: March 26th, 2012, 11:02 AM
  3. Help with adding multiple images to an application
    By Jumbosize in forum Object Oriented Programming
    Replies: 9
    Last Post: February 26th, 2012, 12:52 PM
  4. Saving multiple images
    By Dario in forum Java Theory & Questions
    Replies: 3
    Last Post: January 25th, 2011, 01:59 PM
  5. [SOLVED] Need to display multiple images from database on a webpage
    By raghuprasad in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: May 13th, 2009, 03:15 AM