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.


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

Results 1 to 2 of 2

Thread: Showing a picture in a GUI

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    Default Showing a picture in a GUI

    I'm doing a lending register inwhich different types of objects (books, cd's and films) are represented. I have a GUI consisting of a AbstractTableModel with an ArrayList in it. The different classes (books etc.) all inherit from a class "Item" I've written. When the objects in the list are shown in teh GUI, I want different pictures to appear in the cells, depending of what kind of objet it is. (the first row of the table should show pictures). The classes all have the method getType, and I've written something like:
    PHP Code:
       public Object getValueAt(int rowint col){
    Item i ItemsTable.get(row);
                    switch (
    0: return i.getType();
    1: return i.getTitle();
    2: return i.getOriginator();
    3: return i.getPublicationYear();
    5: return i.islended();
                    default: return 
    I've seen something like a method (i("randomfilename.jpg") ), and i'm trying to use that method, but how do I make it appear in the GUI? i.e what code would do that(in the switch-statement above)?

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: Showing a picture in a GUI

    You first need references to the images (probably in the form of an ImageIcon). You can then define a custom cell renderer for the column in the table you wish to have images in and do the image setting from there. See How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) and also google "images in JTable" and you'll pull up a number of examples.

Similar Threads

  1. Help with a program to make a landscape picture
    By noseeds in forum Java Theory & Questions
    Replies: 1
    Last Post: December 15th, 2009, 10:25 PM
  2. Modify Colors in a Picture
    By theuniverse in forum Java Theory & Questions
    Replies: 0
    Last Post: October 17th, 2009, 04:49 PM
  3. Need help with a Picture!
    By Scout in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2009, 05:33 PM