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
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.
1 Attachment(s)
I've tried out my "theory" above ....
You will have to add code for hiliting the selected image.