Horizontal Dispaly of Images in JList


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Horizontal Dispaly of Images in JList

  1. #1
    Join Date
    Jun 2005
    Posts
    2

    Horizontal Dispaly of Images in JList

    Hi All,
    I had developed an application that displays several images in a JList . The images are displayed vertically. Below is the outline of my code:

    Code:
    JPanel imgpanel1=new JPanel();
    JPanel imgpanel2=new JPanel();
    .....
     
    ImageIcon img1=new ImageIcon("bookimages/img1.jpg");
    ImageIcon img2=new ImageIcon("bookimages/img2.jpg");
    ....
     
    imgpanel1.add(new JLabel(img1));
    imgpanel2.add(new JLabel(img2));
    .......
     
    JList list=new JList();
    list.setCellRenderer(new CustomCellRenderer()); // implements ListCellRenderer
     
    Vector data=new Vector();
    vector.addElement(imgpanel1);
    vector.addElement(imgpanel2);
    ....
     
    list.setListData(data);
     
    Panel mypanel=new Panel();
    mypanel.add(list,BorderLayout.WEST);
    The problem:
    I am unable to display images horizontally in a JList. I've even used the method
    setLayoutOrientation(JList.HORIZONTAL_WRAP).

    I am new to Swing development, please give me an idea to display images horizontally in a JList. . Please help me guys.

    Thanks in advance

  2. #2
    Join Date
    Jun 2005
    Posts
    2
    I need help from your side. Please give me an alternative to JList where in I can display images horizontally and implement events like Mouse Clicks etc.

    Thanks.

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    There may be more "modern" ways to do this,..

    ..but not any I now of;

    How about a plain JPanel, with a 1 row gridlayout contained in a JScrollPane
    with no vertical slidebar.
    Then you define a JPanel extension that displays an image and implements
    MouseListener (it could also be used in conjuctin with an interface that
    defined the callback to the interested parties,... ImageListUser (?)).

    For each image you load you create a new instance of this panel and add it
    to the "horizontal list" panel. Deletion/insertion of elements is done using the
    remove/add & validate methods of the gridpanel.
    eschew obfuscation

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    I've tried out my "theory" above ....

    You will have to add code for hiliting the selected image.
    Attached Files Attached Files
    Last edited by sjalle; 06-13-2005 at 12:09 PM. Reason: Replacesd GridLayout w. FlowLayout - left
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center