Hello all,
Now i am adding the items into the list,
and i have to track while adding the items into the
list.
How can I find out wheher the items are
adding to the list or not?
See java API specification
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html
and
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
// Create a JList that displays the strings in data[]
String[] data = {"one", "two", "three", "four"};
JList dataList = new JList(data);
// The value of the JList model property is an object that provides
// a read-only view of the data. It was constructed automatically.
for(int i = 0; i < dataList.getModel().getSize(); i++) {
System.out.println(dataList.getModel().getElementAt(i));
// you could compare your element with the elements
// which are on the JList here
}
any listener i have to add to the list. what
listener and how can i use it?
for example:
final JList list = new JList(dataModel);
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = list.locationToIndex(e.getPoint());
System.out.println("Double clicked on Item " + index);
}
}
};
list.addMouseListener(mouseListener);