Il 02/08/2010 20:33, Alejandro Vilar ha scritto:
Hi Stefano,/If I use both DataRenderer and ItemRenderer I guess - a wild guess - that the DataRenderer will compute //name + " - " + address// the first time the listButton is initialized and then the ItemRenderer will return the value to show to the user every time he scrolls the list./I will call (name+" - "+address) as displayName from now, it will computed each time that your renderer need it (when is visible, mouse events, highlighted and so on), to avoid this computation all the time you could keep displayName as variable o final value.One approach: public class Customer { private String key, name, address; private String displayName; public Customer(String key, String name, String address) { this.key = key; this.name = name; this.address = address; } public String getDisplayName() {//All the time this conditional is checked(more processor operations)if (displayName == null) { displayName = name + " - " + address; } return displayName; } } Second approach: public class Customer { private String key, name, address; private final String displayName; public Customer(String key, String name, String address) { this.key = key; this.name = name; this.address = address;//All customers with displayName computed from beginning( more memory usage)displayName = name + " - " + address; } public String getDisplayName() { return displayName; } } Renderer: public class CustomerDataRenderer extends ButtonDataRenderer { @Override public void render(Object data, Button button, boolean highlighted) { super.render(data, button, highlighted); if (data instanceof lbtCustomer) { Customer customer = (Customer) data; super.label.setText(customer.getDisplayName()); } } }Both approaches with advantages and disadvantages, remember render() method is called all the time when data is needed to represent/view.
Thank you very much Alejandro, your code is very clear and easy to understand.
Stefano
Regards, Alejandro
-- Dr. Stefano Sancese WatchGuard Certified System Professional - http://www.watchguard.com Socio Clusit - Associazione Italiana per la Sicurezza Informatica ************************************************************************ In God we trust, all others we monitor (National Security Agency) ************************************************************************
smime.p7s
Description: S/MIME Cryptographic Signature
