Anyone have experience reusing "cell renderers" among multiple instances...

I've implemented a 'light' cell renderer that sets all its attributes during the fetch to
getCellRendererComponent()
[in other words, all of the cell renderer instance vars are set during this call, wiping out the last objects settings]
In the hopes of saving memory, I wanted to create one cell renderer instance and share it among 100's of the same type of object. Realizing that all paints should perform on the single threaded GUI-EVENT-THREAD, this operation should be safe.
Anyone try this before?? Is it possible to reuse a single renderer instance among multiple Swing components? I look at the way Swing generates the default renderers if you don't specify one and it always returns a new instance ( the == is false ), yet each instance returned looks almost identical and contains references to the same objects with the same memory addresses.

I'm pretty much sure that sharing one instance is the default behavior. Check out installDefault() of class javax.swing.plaf.basic.BasicListUI. Here, all JList instances are initialized with a single ListCellRenderer instance.
Here's an example:public static void main(String[] arguments) {
        JFrame f = new JFrame();
        Vector v = new Vector();
        for (int i = 0; i < 10; i++)
            v.add(new Integer(i));
        JList l = new JList(v);
        l.setCellRenderer(new DefaultListCellRenderer() {
            private int val;
            public Component getListCellRendererComponent(
                JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {
                if (isSelected) {
                    setBackground(list.getSelectionBackground());
                    setForeground(list.getSelectionForeground());
                } else {
                    setBackground(list.getBackground());
                    setForeground(list.getForeground());
                setEnabled(list.isEnabled());
                setBorder(
                    (cellHasFocus)
                        ? UIManager.getBorder("List.focusCellHighlightBorder")
                        : noFocusBorder);
                val = ((Integer) value).intValue();
                setPreferredSize(new Dimension(val * 12, 12));
                return this;
            protected void paintComponent(Graphics g) {
                g.setColor(getBackground());
                g.fillRect(0, 0, getWidth(), getHeight());
                g.setColor(getForeground());
                for (int i = 0; i < val; i++)
                    g.fillOval(i * 12, 1, 10, 10);
        f.getContentPane().add(new JScrollPane(l));
        f.pack();
        f.show();
    }Hope that helps,
bye

Similar Messages

  • Does anyone have experience with having multiple editors work on the same project from different computers?

    Does anyone have experience with having multiple editors work on the same project from different computers?

    As much as I hate to admit it, YOU ARE RIGHT!
    I will tread lightly on this project.
    Thanks for the sanity check,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Photoshop cs6 won't allow me to highlight my existing text layers. Does anyone have experience with this problem?

    Photoshop cs6 won't allow me to highlight my existing text layers. I select the text tool and the text layer I want to edit, hover over text and each time I attempto to edit a new layer is created. Does anyone have experience with this problem?

    Be sure you go to Adobe's Web Site and make sure there are no Updates for CS6
    http://www.adobe.com
    Remember if you have trouble with a software issue it is the software and not caused by the Mac you are using
    Many users simply don't remember when you upgrade software you normally have to go to 3rd party web sites and update software as well.
    Cheers
    Don

  • Does anyone have experience with unzipping a password-encrypted ZipFile??

    Does anyone have experience with unzipping a password-encrypted ZipFile??
    My Zip Class works fine with every unencrypted file, but when I try to open an encrypted one, i get an error Message ("Encrypted ZIP entry not supported")
    Is ist impossible to unzip encrypted ZIPs???

    I've searched around a little bit and THIS IS THE SOLUTION!
    There is a (beta)version of winzip8 that uses a cli (command line interface)
    So, all you have to do is to implement a Runtime.getRuntime().exec(...) in your java program to call winzip8 and pass the zipfile path and the password.
    Here's the URL: http://www.winzip.com/wzcline.htm

  • Does anyone have experience selling or giving away their Nano?

    I'm considering selling my Nano and hope to replace it with a Touch. My question is, what do I need to do before selling the Nano to a buyer? Do I need to do any preparation?
    What does a buyer need to do to make a used Nano his? Can I just give him the Nano and say download iTunes? Do I need to "release" the Nano in some way?
    Anyone have experience with this?

    Do you really want to give your buyer some games from iTunes?!?
    But maybe that's not such a bad idea, the buyer might be more likely to buy your iPod if games are on it, but if you give him your iPod the games will be synced over, and erased. Select +"Enable disk mode"+ and drag-and-drop your games from iTunes onto it. Then he can drag the games to his own iTunes library.

  • RE: (forte-users) Does anyone have experience using OracleLarge Objects

    hi ,
    A few months ago, I tried a oracle stored procedure with a BLOB parameter,
    but Forte(3.l2) could not recognize the blob variable. I used oracle 8.0
    hth
    suma
    -----Original Message-----
    From: Amin, Kamran [mailto:kamran.aminlendware.com]
    Sent: Thursday, March 29, 2001 2:40 PM
    To: 'Forte User Group'
    Cc: Magaliff, Bill
    Subject: (forte-users) Does anyone have experience using Oracle Large
    Objects (LOB's)?
    Does anyone have experience using Oracle Large Objects (LOB's) -
    specifically the CLOB datatype? Forte supports Oracle LONG's but given that
    Oracle is going to phase out that datatype and they're trying to push users
    towards CLOB's instead of LONG's, I want to find out if Forte can handle it
    and, if so, what we should know about mapping Forte datatypes to the Oracle
    CLOB. [Their compatibility matrix for v3.5 indicates suppport under Oracle
    8.1.x, and CLOB's were introduced back in 8.0.x - but the word from Forte is
    that they currently don't support it.]
    thanks in advance.
    ka
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

    Hi,
    Did you get any solution to this. If yes, please share.
    Thanks,
    Tints

  • Does anyone have experience with Virgin or Boost Mobile?

    I have been with verizon for a long time...I have 4 lines with this service. I have since bought several phones off of craigslist or ebay just so I wouldn't have to be subjected to the tier plan. We use so much data it's crazy. I want the new Samsung Galaxy S4 so bad!!! Grrr! I've even thought about switching to Virgin Mobile or Boost Mobile. We pay so much for our phones now and I know of one guy who has boost mobile and loves it. Does anyone have experience with these providers?

    BC's CRM is part of the package, Salesforce is of course more dedicated. That pretty much sum's up these sorts of use cases.

  • Does anyone have experience with using a Canon Vixia HF M52 Camcorder with Final Cut Express?

    I'm looking to purchase a new camcorder that is compatible with my Mac OS X (10.6.8) that will work well with Final Cut Express 4.0.1  I have downloaded the camcorder support info from Final Cut Express that list many capital camcorders.  I've used Sony tape based camcorders in the past.  I'm looking for High Definition.  I can stick with a tape based camcorder, but thought I would look at the Canon Vixia HF M52 as an alternative, which is listed as compatible.  I would like to download directly from the camera to FCE.  I film in the wilderness, like having an optical zoom of 20 or greater (yes, I use a small tripod). Does anyone have experience with the Canon Vixia?  And if not, but you really like another camcorder that you can recommend, what is it?

    The Vixia HF M52 is an AVCHD camcorder and should work perfectly fine with Final Cut Express 4 (4.0.1).
    The published "camcorder support list" has never been up to date and I would not take it to be a definitive list of compatible camcorders.
    One note, however, the Vixia HF M52 supports a number of different shooting modes.  I suggest sticking with the AVCHD 1920 x 1080i / 60 fps mode for use with FCE.   FCE does not support progressive modes except in 720p25/30 (which the M52 does not seem to shoot anyway); nor does FCE support any 24 fps modes.

  • HT1689 Does anyone have experience downloading audio books while in Europe from a U.S. account?

    Does anyone have experience downloading audio books in Europe using a U.S. account?

    The terms of the iTunes Store state that you agree not to use or even attempt to use the US iTunes Store from outside the US. Sorry, then, but we cannot discuss that issue here.
    Regards.

  • Anyone have experience about Mandrake9.1 + oracle instant client +php

    Anyone have experience about Mandrake9.1 + oracle instant client +php
    ======================
    Now i need your help about
    1. Install oracle instant client on my MDK9.1
    2. and want it so success and nice work ( PHP+Oracle Instant Client )
    ( PHP that can use oci8 tag : support oracle tag ) sir
    Can you help me and send me how-to/guide/link that "It's work !! " ? sir
    Thank you very much
    Pratchaya

    Use --with-oci8-instant-client option.
    Following links will help you:
    php + openldap +oci8 instantclient
    http://www.oracle.com/technology/pub/notes/technote_php_instant.html

  • Does anyone have experience with migrating applications from iAS6.0 SP2 to SP3? Did it go smoothly or are there problems to be expected?

     

    Hi,
    I haven't. But, there are lots of changes from each service packs,
    henceforth you may have to stick to what the documentation says to avoid
    the errors that shoots up. Again, the errors depends upon how you have
    coded your application. Please let me know if you have encountered any
    errors and the messages for me to help you.
    Regards
    Raj
    Peter Clijsters wrote:
    Does anyone have experience with migrating applications from iAS6.0
    SP2 to SP3? Did it go smoothly or are there problems to be expected?
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • Does anyone have experience with error 504 when trying to download a podcast?

    Does anyone have experience with error 504 when trying to download a podcast?  I've been a subscriber for two years without issue and in the last two days can't download this particular podcast (everything else is working fine - music, other podcasts, etc)

    The album was released on the 27th March this year, so the error occurred almost immediately after it was supposedly available.
    In the manage pre-orders section of my account, it says AVAILABLE but does not give me any choice over whether to download it, just to cancel it. Is this normal?
    iTunes customer services reset my password and tried to download the album themselves, but they also got the 5002 error, so it's been passed off to the engineers. How long does that usually take?
    If anyone has any other suggestions, it would be greatly appreciated.

  • Does anyone have experience with Iogear GBU 421? My MacPro has no in-built Bluetooth.

    Does anyone have experience with Iogear GBU 421? My MacPro has no in-built Bluetooth.

    My 2010 Mac Pro does have built in bluetooth but I use the IOGear GBU421 instead.  That's because the built in bluetooth on the mac pro suck$ if you are more than about 3 feet from the machine.
    See the descussion: Poor Bluetooth reception and jerky mouse
    It works but you need to get used to its "quirks".  If you sleep your machine like I do the dongle is off because there is no USB power when sleeping for the dongle.  So you need some wired USB device to wake the machine.  In my case I use my wired keyboard.
    When waking up it doesn't always become paired immediately (maybe 30% of the time).  Then you need to flip the mouse switch to get it active.  Interesting enough I don't have that problem with the trackpad.
    Most of the time, in the rear occasions I reboot my machine, the mouse is ready to go.
    Once you get used to the "quirks" it's no big deal.  Hey, for about $9 what do you want?
    By the way I also always keep a wired mouse attached as a backup.

  • Does anyone have experience for disk damage and loss?

    Does anyone have experience for disk damage and
    loss for B1?  What's the procedure to get new one?
    Any cost involved.
    Regards,
    Kenneth

    Hi Kenneth
    Usualy we take the strongest measures to avoid that and never let it come to that. You should of had back up's running on and off site. How bad is your problem?? I'm assuming you are talking abou a hard drive that is faulty. Have you tried restarting in Safe Mode??
    You get experts that can retrieve data from a hard drive depending how bad the problem is. It usualy cost more than the Hard drive......but if you are desperate and value your data you'll do it.
    Hope this helps

  • Anyone have experience with ESET Cybersecurity?

    Anyone have experience with ESET Cybersecurity?  If yes, good, not so good, or forget it?
    Thanks
    <Email Edited by Host>

    Since it is AV software and there are no virus on the Mac, I suggest you forget it.
    Allan

Maybe you are looking for