Tilføje til et panel efter init
jeg opretter nogle panels i forbindelse med min constructor.Senere (ved action fra listen) skal det miderste panel så fyldes med nogle billeder, de kommer bare aldrig, hvorfor ?
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
import javax.swing.event.*;
import java.awt.event.*;
public class photoClient extends JFrame implements ListSelectionListener, MouseListener{
private DefaultListModel dlmalbumList;
private JPanel albumList = new JPanel();
private JPanel currentAlbum = new JPanel();
private JPanel photoInfo = new JPanel();
private Vector albums, images;
private XmlRpcFacade xml;
public photoClient() {
xml = XmlRpcFacade.getInstance();
try {
jbInit();
initXML();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
void jbInit() throws Exception {
this.getContentPane().setLayout(new BorderLayout());
albumList.setLayout(new GridLayout(1,1));
currentAlbum.setLayout(new GridLayout(3,2));
photoInfo.setLayout(new GridLayout(3,2));
this.getContentPane().add(albumList, BorderLayout.WEST);
this.getContentPane().add(currentAlbum, BorderLayout.CENTER);
this.getContentPane().add(photoInfo, BorderLayout.EAST);
dlmalbumList = new DefaultListModel();
JList albumJlist = new JList(dlmalbumList);
albumList.add(albumJlist);
albumJlist.addListSelectionListener(this);
JLabel itest1 = new JLabel("itest1");
JLabel itest2 = new JLabel("itest2");
JLabel itest3 = new JLabel("itest3");
JLabel itest4 = new JLabel("itest4");
JLabel itest5 = new JLabel("itest5");
JLabel itest6 = new JLabel("itest6");
photoInfo.add(itest1);
photoInfo.add(itest2);
photoInfo.add(itest3);
photoInfo.add(itest4);
photoInfo.add(itest5);
photoInfo.add(itest6);
}
private void initXML()
{
albums = xml.listAlbums();
for (int i=0; i<albums.size(); i++)
{
Album album = (Album)albums.get(i);
dlmalbumList.addElement(album);
}
}
public void valueChanged(ListSelectionEvent e) {
JList jlist = (JList)e.getSource();
if (!e.getValueIsAdjusting())
{
int index = jlist.getSelectedIndex();
Album album = (Album) albums.get(index);
System.out.println(album);
images = xml.listAlbum(index + 1);
updatealbum();
}
}
private void updatealbum()
{
// currentAlbum.removeAll();
for (int i=0; i<images.size(); i++)
{
Photo photo = (Photo)images.get(i);
int id = photo.getID();
ImageIcon ii = xml.getThumb(id);
ImageLabel label = new ImageLabel(id, ii);
currentAlbum.add(label);
label.addMouseListener(this);
System.out.println(photo);
}
currentAlbum.repaint();
repaint();
}
public static void main(String[] args) {
photoClient photoclient = new photoClient();
photoclient.setSize(450,450);
photoclient.show();
}
public void mouseClicked(MouseEvent e) {
ImageLabel label = (ImageLabel)e.getSource();
System.out.println(label);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
