Re: efficiency of JList setElementAt()
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Dec 2005 00:05:51 +0000
Raymond Cruz wrote:
The problem isn't very sensitive to how much is on the screen. For the examples given, approximately 75% of the list was outside of the scroller's viewport. In fact, if the frame that displays the JList is minimized to a null display, the timing improves by only about 15%.
You probably need to use a profiler on it (or do a ctrl-\ or ctrl-break on it randomly from the console). Possibly it is something to do with validating the layout, the model/list elements might be slow or perhaps you are extremely short on video RAM.
I wrote a little benchmark. On 266 MHz PII it settled down to 3-3.5% CPU. On my 2.26ish GHz Celeron, it came in comfortably under 1%.
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*;
class ListSpeed {
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
swing();
}
});
}
private static final java.util.Random random =
new java.util.Random();
private static void swing() {
assert java.awt.EventQueue.isDispatchThread();
JFrame frame = new JFrame("ListSpeed");
final DefaultListModel model = new DefaultListModel();
for (int ct=0; ct<50; ++ct) {
model.addElement("some data "+new java.util.Date());
}
final JList list = new JList(model);
frame.add(list);//new JScrollPane(list));//
frame.pack();
frame.setVisible(true);
new javax.swing.Timer(1000 /* millis */, new ActionListener() {
private boolean set;
public void actionPerformed(ActionEvent event) {
model.setElementAt(
"new data "+new java.util.Date(),
random.nextInt(model.size())
);
}
}).start();
}
}Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- Follow-Ups:
- Re: efficiency of JList setElementAt()
- From: Raymond Cruz
- Re: efficiency of JList setElementAt()
- References:
- efficiency of JList setElementAt()
- From: Raymond Cruz
- Re: efficiency of JList setElementAt()
- From: Thomas Hawtin
- Re: efficiency of JList setElementAt()
- From: Raymond Cruz
- efficiency of JList setElementAt()
- Prev by Date: Re: efficiency of JList setElementAt()
- Next by Date: Re: efficiency of JList setElementAt()
- Previous by thread: Re: efficiency of JList setElementAt()
- Next by thread: Re: efficiency of JList setElementAt()
- Index(es):
Relevant Pages
|