Results 1 to 6 of 6

Thread: What is the use of DefaultListCellRenderer class?

  1. #1
    Join Date
    Dec 2009
    Posts
    41

    What is the use of DefaultListCellRenderer class?

    Hi All,

    I am new to the programming field. I just started to learn java programming. The class and object concept of java sounds very complex. I am not able to understand the DefaultListCellRenderer class concept. I don't have any idea about the use of DefaultListCellRenderer class. I have searched many java book, but didn't get enough details. I you know anything about the DefaultListCellRenderer class of java, then please share it with me. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is the use of DefaultListCellRenderer class?

    Hi,

    Implementation: This class overrides validate, revalidate, repaint, and firePropertyChange solely to improve performance. If not overridden, these frequently called methods would execute code paths that are unnecessary for the default list cell renderer. If you write your own renderer, take care to weigh the benefits and drawbacks of overriding these methods.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the use of DefaultListCellRenderer class?

    Before using DefaultListCellRenderer class, you must be aware about following it's methods:
    • firePropertyChange(String prName, short oldVal, short newVal)
    • firePropertyChange(String prName, Object oldVal, Object newVal)
    • firePropertyChange(String prName, long oldVal, long newVal)
    • repaint(long tm, int x1, int y1, int width1, int height1)
    • firePropertyChange(String prName, int oldVal, int newVal)

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: What is the use of DefaultListCellRenderer class?

    Hi friend,

    Following example will give you some idea about the use of 'DefaultListCellRenderer class' of java:
    Code:
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
    
    public class CustomBorderDM
     {
      public static void main(String args[]) {
        String labels01[] = { "A", "B", "C", "D","E", "F", "G", "H","I", "J" };
        JFrame gek = new JFrame("Custom Border");
        gek.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container contentPane = gek.getContentPane();
        JList jlist1 = new JList(labels);
        ListCellRenderer renderer = new FocusedTitleListCellRenderer();
        jlist1.setCellRenderer(renderer);
        JScrollPane sp1 = new JScrollPane(jlist1);
        contentPane.add(sp1, BorderLayout.CENTER);
        gek.setSize(400, 200);
        gek.setVisible(true);
      }
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What is the use of DefaultListCellRenderer class?

    If you want to know about nested classes of DefaultListCellRenderer class, then please refer following list:
    1. DefaultListCellRenderer.UIResource
    2. Component.FlipBufferStrategy
    3. Container.AccessibleAWTContainer
    4. Component.AccessibleAWTComponent
    5. JLabel.AccessibleJLabel

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What is the use of DefaultListCellRenderer class?

    Hi,

    See if something below code can help you to know about DefaultListCellRenderer class:
    Code:
    class ColorCellRendererDEMO implements DefaultListCellRenderer
     {
      protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
    
     
      private final static Dimension preferredSize = new Dimension(0, 10);
    
      public Component getListCellRendererComponent(JList list1, Object val, int idx,
          boolean isSelected, boolean cellHasFocus) {
        JLabel renderer1 = (JLabel) defaultRenderer.getListCellRendererComponent(list1, val1, idx,
            isSelected, cellHasFocus);
        if (val instanceof Color) {
          renderer1.setBackground((Color) val);
        }
        if(cellHasFocus || isSelected){
          renderer1.setBorder(new LineBorder(Color.DARK_GRAY));
        }else{
          renderer1.setBorder(null);
        }
        
        renderer1.setPreferredSize(preferredSize);
        return renderer1;
      }
    }

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. What is the difference between Local class and global class in C++?
    By Dëfrim in forum Software Development
    Replies: 4
    Last Post: 03-01-2011, 10:44 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,152,798.16105 seconds with 16 queries