hi~ all
one>
list.setModel(listModel);
list.updateUI();
two>
list.setModel(listModel);
//list.updateUI();
It makes a difference..
and I'm learning english and I'm not fluent in english..
but don't worry.. I'm great reading..^^
It makes a difference..
please tell me the reason..
thanks..
=================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
public class DelegateEx extends JFrame implements ActionListener {
private JTextField tf = new JTextField();
private DelegateListModel listModel = new DelegateListModel();
private JList list = new JList();
private JScrollPane scroll = new JScrollPane(list);
public DelegateEx() {
super("UI-Model Ex");
JPanel cpPane = (JPanel)getContentPane();
cpPane.setLayout(new BorderLayout());
cpPane.add(tf, BorderLayout.NORTH);
cpPane.add(scroll, BorderLayout.CENTER);
tf.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == tf) {
String str = tf.getText();
if (str.length() < 0) return;
listModel.addRow(str);
///////////////////////////////
list.setModel(listModel);
list.updateUI();
///////////////////////////////
tf.select(0, str.length());
}
}
public static void main(String args[]) {
DelegateEx frm = new DelegateEx();
frm.setVisible(true);
frm.pack();
}
}
class DelegateListModel extends AbstractListModel {
private Vector listData = new Vector();
public Vector getListData() {
return listData;
}
public void addRow(String sItem) {
if (sItem == null) return;
listData.addElement(sItem);
}
public int getSize() {
return listData.size();
}
public Object getElementAt(int index) {
return listData.get(index);
}
}
Andrew Thompson - 18 Feb 2004 14:17 GMT
> hi~ all
hi~ one
> one>
> list.setModel(listModel);
[quoted text clipped - 5 lines]
>
> It makes a difference..
yeeees it does. The second
one does not update the
user interface. ;-) (ducks)
--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology