JList with few imageIcon

I need a few imageIcon in a single JList. I was trying to get help from "The Java Tutorial" but failed.
If someone know please tell me the method.
Thanks in advance.

There is no trick to doing this. You simply add multiple ImageIcons to the ListModel.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • JList with ImageIcon

    Hello,
    Can I have JList with an ImageIcon beside it?e.g
    "imageicon" "sometext"
    code snippet would be helpful.
    Thanks

    Hello,
    little improvement-update, custom ListCellRenderer now checks whether object is a String only or a JLabel with an ImageImage. You can use it for both versions of JLists.
    import javax.swing.*;
    import java.awt.*;
    public class ImageTextList extends JFrame
         private static String[]text = new String[10];
         private static JLabel[]labels = new JLabel[text.length];
         private static ImageIcon[] icons = new ImageIcon[labels.length];
         static
              for(int i=0; i<text.length; i++)
                   text[i]   = "Images " + (i+1);
                   icons[i]  = new ImageIcon(     "../testproject/img/" + (i+1) + ".jpg");
                   labels[i] = new JLabel(text, icons[i], JLabel.CENTER);
         public static void main(String[] args)
              new ImageTextList();
         public ImageTextList()
              super("Image+Text in a JList");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //test with labels and text
              JList list = new JList(labels);
              list.setCellRenderer(new MyCellRenderer());
              getContentPane().add(new JScrollPane(list));
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
         class MyCellRenderer extends JLabel implements ListCellRenderer
              private JLabel label = null;
              // This is the only method defined by ListCellRenderer.
              // We just reconfigure the JLabel each time we're called.
              public Component getListCellRendererComponent(
                   JList list,
                   Object value,
              // value to display
              int index, // cell index
              boolean isSelected, // is the cell selected
              boolean cellHasFocus) // the list and the cell have the focus
                   String s = value.toString();
                   ImageIcon icon = null;
                   //checks whether the source is a label or another object(String only)
                   if(value instanceof JLabel)
                   {System.out.println("label");
                        label = (JLabel)value;
                        icon = (ImageIcon)label.getIcon();
                        s = label.getText();
                   setText(s);
                   setIcon(icon);
                   if (isSelected)
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                   } else
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   setEnabled(list.isEnabled());
                   setFont(list.getFont());
                   setOpaque(true);
                   return this;
    regards
    Tim

  • JList with aligned pictures

    What would be the best way to make a JList with a picture for each item?
    I have all the pictures loaded as ImageIcons btw.

    Write a custom list renderer, see http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/ListCellRenderer.html
    Then, to get the text aligned, you'll need to use the setIconTextGap method of JLabel. If the maximum icon width is 16 and your current icon is 13 pixels wide, then just set the icon-text-gab to 3.
    Something like this:
    import java.awt.*;
    import javax.swing.*;
    public class Dummy
         public static void main(String [] args)
              JList list = new JList(new Object[]{
                   new JLabel("small", new ImageIcon("d:/java/resources/java logo 16x16.png"), JLabel.LEFT),
                   new JLabel("large", new ImageIcon("d:/java/resources/java logo 32x32.png"), JLabel.LEFT)
              list.setCellRenderer(new MyCellRenderer());
              JFrame f = new JFrame();
              f.getContentPane().add(list);
              f.setSize(400,400);
              f.setVisible(true);
         static class MyCellRenderer extends JLabel implements ListCellRenderer
              public MyCellRenderer()
                   setOpaque(true);
              public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                   JLabel label = (JLabel)value;
                   setText(label.getText());
                   setIconTextGap(4 + 32 - label.getIcon().getIconWidth());
                   setIcon(label.getIcon());
                   setBackground(isSelected ? Color.red : Color.white);
                   setForeground(isSelected ? Color.white : Color.black);
                   return this;

  • Populating JList with a single database column

    Hi all,
    I have the following code and i'm trying to popluate the JList with a particular colum from my MySQL Database..
    how do i go about doing it??
    Can some one please help
    import java.awt.*; import java.awt.event.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.*; public class RemoveD extends JDialog {     private JList list;     private JButton removeButton;     private JScrollPane scrollPane;     private Connection conn = null;     private Statement stat = null;         public RemoveD(Frame parent, boolean modal) {         super(parent, modal);         initComponents();     }     private void initComponents() {         scrollPane = new JScrollPane();         list = new JList();         removeButton = new JButton();         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);         getContentPane().setLayout(new GridLayout(2, 0));         scrollPane.setViewportView(list);         getContentPane().add(scrollPane);         removeButton.setText("Remove");         removeButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent evt) {                 removeButtonActionPerformed(evt);             }         });         getContentPane().add(removeButton);         pack();         try {             Class.forName("com.mysql.jdbc.Driver");                    } catch (ClassNotFoundException ex) {             ex.printStackTrace();                    }         try {             String userID = "";             String psw = "";             String url;             url = "jdbc:mysql://localhost:3306/names";             conn = DriverManager.getConnection(url, userID, psw);             stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,                     ResultSet.CONCUR_READ_ONLY);             stat.close();             conn.close();         } catch (SQLException ex) {             ex.printStackTrace();         }     }     private void removeButtonActionPerformed(ActionEvent evt) {     }     public static void main(String args[]) {         EventQueue.invokeLater(new Runnable() {             public void run() {                 RemoveD dialog = new RemoveD(new JFrame(), true);                 dialog.addWindowListener(new WindowAdapter() {                     public void windowClosing(WindowEvent e) {                         System.exit(0);                     }                 });                 dialog.setVisible(true);             }         });     } }

    I figured out how to do it

  • JTable/jlist with word wrapping cells?

    Hello all,
    I got a simple looking problem but i can't seem to find any working solution for it:
    A jtable or jlist with cells that wordwrap text (cells differ in height).
    I found many examples on groups.google and this forum but they all seem to suffer a 100% processor load when 2 or more cells differ in height.
    Can anyone point me to a working example?
    Kind regards,
    Twan

    Thanks! That's a real live saver.
    I had been looking for a solution for several days, strange google did not yet found the mentioned page, cause it contains usefull information.
    I've just implemented the multiline table and it works without any problems and most important without 100% cpu usage.
    The bucks are comming your way ;-)

  • Help with updating imageIcon in JTable

    Hi All
    Please I am hoping that some out there will know what is going on with this
    I am setting a Cell with a ImageIcon with this code
            Object[] data = {
                rSet.getString(1),
                new ImageIcon("imagesTest/" + "check" + rSet.getString(2) + ".png"),
                rSet.getString(2),
                "yes",
                rSet.getString(3)};
            model.addRow(data);and this work fine as I have this set to the table
          public Class getColumnClass(int c) {
            return getValueAt(1, c).getClass();
          }Now I want to update the ImageIcon with a new image that I create
    and I am trying to set the new ImageIcon to the cell with this code
          model.setValueAt(new ImageIcon("imagesTest/" + "check" +table.getValueAt
    (table.getSelectedRow(), 2) +".png"), table.getSelectedRow(), 1);but it does not want to paint it
    I have tried
    repaint();
    super.repaint();
    revalidate();I have also tried reloading the data by removing all the rows in the model with this
        model.setRowCount(0);
       then reloading the data.
    It seams like it holds ImageIcom in memory or something .
    Has anyone got an idea on how I can get this to work
    p.s I don't have the full code to show as it is hard to pull it apart.
    I hope I have given enough code to so you what is going on.
    Thanks for any insight into this
    Craig

    You should write an appropriate cell renderer.
    If the cell is defined editable, you'd also need cell editor.

  • Populatin a JList with elements from a DB (access here)

    last year i was able to populate a JList with data from a database
    however this year something doesnt work
    this is last year
    public String[] getOnderwerpen()
    System.out.println(theConnection==null?" connection null ":" connection niet null ");
    String []locaties = new String[30];
    ArrayList returnLijst;
    returnLijst = new ArrayList();
    ArrayList arraylist;
    arraylist = new ArrayList();
              String[] deLocaties = null;
    try{
    String onderwerpQuery = "SELECT OnderwerpID FROM Onderwerp order by OnderwerpID";
    Statement statement = theConnection.createStatement();
    System.out.println(statement==null?" statement null ":" statement niet null ");
    statement.execute(onderwerpQuery);
    ResultSet result = statement.getResultSet();
    System.out.println(result==null?" ResultSet null ":" ResultSet niet null ");
    int i = 0;
                   while(result.next())
              //          locaties[i] = result.getString("OnderwerpID");
    locaties[i] = result.getString("OnderwerpID");
                                            i++;
    deLocaties = new String;
              for (int j=0;j<deLocaties.length;j++)
                   deLocaties[j] = locaties[j];
              sorteerStringArray(deLocaties);
    }//end-try
    catch (Exception e) {
    e.printStackTrace();
    return deLocaties;
    & this is what i did this year
    public String[] getbedrijfNaam()
              String[] bedrijfsNamen = new String[Constanten.aantalBedrijven];
              String[] deBedrijfsNamen = null;
         System.out.println(theConnection==null?" connection null ":" connection niet null ");
         System.out.println("test this");
         try{
         String onderwerpQuery = "SELECT naam FROM organisatie";
         Statement statement = theConnection.createStatement();
         System.out.println(statement==null?" statement null ":" statement niet null ");
         statement.execute(onderwerpQuery);
         ResultSet result = statement.getResultSet();
         int i = 0;
                        while(result.next())
                             bedrijfsNamen[i] = result.getString();
                                                 i++;
                        deBedrijfsNamen = new String[i];
                   for (int j=0;j<deBedrijfsNamen.length;j++)
                        deBedrijfsNamen[j] = bedrijfsNamen[j];
                   sorteerStringArray(deBedrijfsNamen);
                   statement.close();
                   //theConnection.close();
         }//end-try
         catch (Exception e) {
         e.printStackTrace();
         return deBedrijfsNamen;
    is there something here thats not right
    or does this no longer work because of the changes made in 1.5

    last year i was able to populate a JList with data from a database
    however this year something doesnt work
    this is last year
    public String[] getOnderwerpen()
    System.out.println(theConnection==null?" connection null ":" connection niet null ");
    String []locaties = new String[30];
    ArrayList returnLijst;
    returnLijst = new ArrayList();
    ArrayList arraylist;
    arraylist = new ArrayList();
              String[] deLocaties = null;
    try{
    String onderwerpQuery = "SELECT OnderwerpID FROM Onderwerp order by OnderwerpID";
    Statement statement = theConnection.createStatement();
    System.out.println(statement==null?" statement null ":" statement niet null ");
    statement.execute(onderwerpQuery);
    ResultSet result = statement.getResultSet();
    System.out.println(result==null?" ResultSet null ":" ResultSet niet null ");
    int i = 0;
                   while(result.next())
              //          locaties[i] = result.getString("OnderwerpID");
    locaties[i] = result.getString("OnderwerpID");
                                            i++;
    deLocaties = new String;
              for (int j=0;j<deLocaties.length;j++)
                   deLocaties[j] = locaties[j];
              sorteerStringArray(deLocaties);
    }//end-try
    catch (Exception e) {
    e.printStackTrace();
    return deLocaties;
    & this is what i did this year
    public String[] getbedrijfNaam()
              String[] bedrijfsNamen = new String[Constanten.aantalBedrijven];
              String[] deBedrijfsNamen = null;
         System.out.println(theConnection==null?" connection null ":" connection niet null ");
         System.out.println("test this");
         try{
         String onderwerpQuery = "SELECT naam FROM organisatie";
         Statement statement = theConnection.createStatement();
         System.out.println(statement==null?" statement null ":" statement niet null ");
         statement.execute(onderwerpQuery);
         ResultSet result = statement.getResultSet();
         int i = 0;
                        while(result.next())
                             bedrijfsNamen[i] = result.getString();
                                                 i++;
                        deBedrijfsNamen = new String[i];
                   for (int j=0;j<deBedrijfsNamen.length;j++)
                        deBedrijfsNamen[j] = bedrijfsNamen[j];
                   sorteerStringArray(deBedrijfsNamen);
                   statement.close();
                   //theConnection.close();
         }//end-try
         catch (Exception e) {
         e.printStackTrace();
         return deBedrijfsNamen;
    is there something here thats not right
    or does this no longer work because of the changes made in 1.5

  • Resizing a JList with variable row heights, not updating the "picture"

    Firstly I would like to apologize for posting this Swing question here, but I was unable to find the Swing category, if someone could direct me to that I would be most grateful.
    Ok, so in abstract what I am trying to do is have a JList with resizable rows to act as a row header for a JTable (exactly like the row headers in OO Calc or MS Excel).
    What I have is a RowHeaderRenderer:
    public class RowHeaderRenderer extends JLabel implements ListCellRendererand it has a private member:
    private Vector<Integer>        _rowHeights            = new Vector<Integer>();which contains a list of all the variable row heights.
    Then there is my getListCellRendererComponent method:
        public Component getListCellRendererComponent(    JList         list,
                                                          Object        value,
                                                          int           index,
                                                          boolean       isSelected,
                                                          boolean       cellHasFocus)
            // Make sure the value is not null
            if(value == null)
                this.setText("");
            else
                this.setText(value.toString());
            // This is where height of the row is actually changed
            // This method is fed values from the _rowHeights vector
            this.setPreferredSize(new Dimension(this.getPreferredSize().width, _rowHeights.elementAt(index)));
            return this;
        }And then I have a row header:
    public class RowHeader extends JList implements TableModelListener, MouseListener, MouseMotionListenerand you may be interested in its constructor:
        public RowHeader(JTable table)
            _table = table;
            _rowHeaderRenderer = new RowHeaderRenderer(_table);
            this.setFixedCellWidth                        (50);
            this.setCellRenderer                        (_rowHeaderRenderer);
            // TODO: grab this value from the parent view table
            JScrollPane panel = new JScrollPane();
            this.setBackground(panel.getBackground());
            this.addMouseMotionListener                    (this);
            this.addMouseListener                        (this);
            this.setModel                                (new DefaultListModel());
            table.getModel().addTableModelListener        (this);
            this.tableChanged                            (new TableModelEvent(_table.getModel()));
        }and as you can see from my mouse dragged event:
        public void mouseDragged(MouseEvent e)
            if(_resizing == true)
                int resizingRowHeight = _rowHeaderRenderer.getRowHeight(_resizingRow);
                _rowHeaderRenderer.setRowHeight(_resizingRow, resizingRowHeight + (e.getPoint().y - _cursorPreviousY));
                _cursorPreviousY = e.getPoint().y;  
        }all I am doing is passing the rowHeaderRenderer the values the currently resizing row should be, which works fine. The values are being changed and are accurate.
    The issue I am having is that while this dragging is going on the row does not appear to be resizing. In other words the "picture" of the row remains unchanged even though I change the values in the renderer. I tried calling:
    this.validate();and
    this.repaint();at the end of that mousedDragged method, but to no avail, neither of them worked.
    Again, I verified that I am passing the correct data in the RowHeaderRenderer.
    So, anyone have any ideas how I should get the image of the RowHeader (JList) to update after calling my MouseDragged event?
    Thank you for your time,
    Brandon

    I was able to fix this some time ago. Here is the solution:
         public void mouseDragged(MouseEvent e)
              if(_resizing == true)
                   int newHeight = _previousHeight + (e.getPoint().y - _cursorPreviousY);
                   if(newHeight < _minRowHeight)
                        newHeight = _minRowHeight;
                   _rowHeaderRenderer.setRowHeight(_resizingRow, newHeight);
                   _table.setRowHeight(_resizingRow, newHeight);
              this.updateUI();
         }

  • CFSTKE* Queues with few entries executing for long durations  (10 hrs)

    In APO 7.0 the CFSTKE* Queues with few entries executing for long durations  (10 hrs)
    Below are the FM from the queue 
    /SAPAPO/CIF_IRQ_REDUCT_INBOUND
    /SAPAPO/CIF_STOCK_INBOUND
    /SAPAPO/CIF_SL_DOC_INBOUND
    /SAPAPO/CIF_SL_DOC_INBOUND
    Do any one have the same problem and any fixes ?
    Thank You

    Hi Aravind,
    What is the status of your queue:
    Is it in status running, ready or sysfail?
    If it is in "Running" status since last 10 hours then check the following things:
    Check SM51 and see if you find a long running process, see if it is trying to do a sequential read on some table.
    If yes then ask your Basis team to run ST04 and see what index it is using,
    If that is also fine then ask them to check stat on that table.
    Builiding stat may help if a read on table is taking long time and index which is being picked up is correct.
    Your basis team should be able to help you.
    I hope it helps.
    Thanks,
    Anupam
    Edited by: Anupam Sengar on Aug 11, 2011 12:06 AM

  • Synchronize JList with JScrollPane

    hi all,
    I want to automatically move the scroll in the JScrollPane when I change the selected position in the JList with setSelectedIndex, right now the list is correctly selected, but the scroll remains on the top, how could I move it to position the list to see the selected item?
    thanks!
    mykro

    JComponent has a scrollRectToVisible method you could use along with JList's getCellBounds method. Maybe register a ListSelectionListener with the list, then in valueChanged get the newly selected cell's bounds from getCellBounds and call scrollRectToVisible on the JList with the cell bounds.

  • Error connecting with Few versions of Oracle

    I wrote an MFC based application in Visual C++ to make the connection with Oracle Database. ADO Control is used to make connection. Following is the Connection String:
    "Provider=MSDAORA;User Id=Scott;Password=Tiger;Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SID = edox)));"
    I am able to connect with few versions of oracle like 8.0.5.0.0 and 9.0.1.1.1
    But few versions are not accepting this connection string. Like Oracle 9i, Release 1.0.2. What could be the reason of this problem?
    Another thing that noticed with 8.0.6.0.0 is that when i start the oracle service, and try to connect, it refuces connection, but next time it accepts the connection request...

    Another thing i noticed is if i connect the SQL+ software, it continues working. But if i close the session of sql+, my other application stops working...Strange.

  • Traversing JList with arrow keys

    I've got a small problem when i try to traverse a JList with the arrow keys. When I'm at the first index of the list and press the UP arrow, I want to select the last index of the list.
    switch (keyCode){
            case VK_UP:
                    if(list.isSelectedIndex(list.getFirstVisibleIndex()))
                        list.setSelectedIndex(list.getLastVisibleIndex());
                    break;
    }When I use this code, the program selects the second last index (not the last). How can I fix this problem?
    Any suggestions will be appreciated.

    I found this thread useful but ultimately solved this another way using key binds. Maybe someone will find this useful.
    public MyDialogConstructor() {
        bindKeys();
    private void bindKeys() {
              InputMap inputMap = getJList().getInputMap(JComponent.WHEN_FOCUSED);
              KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
              inputMap.put(key, "jlist:UP");
              getJList().getActionMap().put("jlist:UP", new AbstractAction() {
                   private static final long serialVersionUID = 1L;
                   public void actionPerformed(ActionEvent e) {
                        if (getJList().isSelectedIndex(getJList().getFirstVisibleIndex())) {
                             getJList().setSelectedIndex(getJList().getLastVisibleIndex());
                        } else {
                             getJList().setSelectedIndex(getJList().getSelectedIndex() - 1);
              key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
              inputMap.put(key, "jlist:DOWN");
              getJList().getActionMap().put("jlist:DOWN", new AbstractAction() {
                   private static final long serialVersionUID = 1L;
                   public void actionPerformed(ActionEvent e) {
                        if (getJList().isSelectedIndex(getJList().getLastVisibleIndex())) {
                             getJList().setSelectedIndex(getJList().getFirstVisibleIndex());
                        } else {
                             getJList().setSelectedIndex(getJList().getSelectedIndex() + 1);
         }

  • Scanning (Into JPEG) of Plain Paper with few graphics results into multiple images on HP 3545

    Scanning (Into JPEG) of Plain Paper with few graphics results into multiple images.
    Whenever I scan a page which is almost a white paper, but has some graphics on it, then the Scanned Files is not a single, rather it becomes in multiple parts e.g. circle in one jpeg file, square in another jpeg file. However the scanning to PDF works fine. Please let me know if this is manufacturing defect or defect in the product I purchased. 

    This only happens if I scan plain paper with few graphics. But scan to jpeg is working fine if the page has multiple objects

  • JList with Images for solitaire?

    could i use JList with gif images of cards for Solitaire(klondike)? if i have 7 vertical panes and one JList in each pane? or is this impossible?

    but that solution didnt work for me1) Where in the posting did you state that?
    2) if it doesn't work then you are doing something wrong.
    I think you have a better chance with your original approach. I don't see how a JList would work.

  • JList with LineBorder think=2

    hello all
    i am writing a look and feel .
    and when i have a JList with LineBorder with thinness = 2 and a item is selected ,
    i cant see the complete text of the selected item
    my question is there a simple way to make this work
    without changing the list preferred size inside my application ?
    thank you
    here is an example
    (please select the third item 'ccccccccccccccc')
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.border.LineBorder;
    public class DialogTest extends JDialog{
      public DialogTest(JFrame f){
        super(f);
        JList list = new JList(new String[]{"aaaaaaaaaaaa" ,"bbbbbbbbbbbbbbb" ,"cccccccccccccccccc"});
        list.setCellRenderer(new DefaultListCellRenderer(){
          public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if(isSelected){
              setBorder(new LineBorder(Color.GREEN ,2));
            }else{
              setBorder(null);
            setText(value.toString());
            return this;
        setLayout(new BorderLayout());
        add(new JScrollPane(list) ,BorderLayout.CENTER);
        pack();
      public static void main(String[] args){
        DialogTest t = new DialogTest(new JFrame());
        t.setVisible(true);
    }

    ok, thanks now this works on the demo also for me.
    but when settings my UI ,i get same result
    i want this border no mater what Render the user will put
    this is what i do
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.ComponentOrientation;
    import java.awt.Graphics;
    import java.awt.Insets;
    import java.awt.Rectangle;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComponent;
    import javax.swing.JList;
    import javax.swing.ListCellRenderer;
    import javax.swing.ListModel;
    import javax.swing.ListSelectionModel;
    import javax.swing.border.CompoundBorder;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.LineBorder;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicListUI;
    import org.jtpc.gui.borders.RoundBorder;
    import org.jtpc.gui.defaultTheme.FocusBorderHandler;
    import org.jtpc.utils.JTPCThemeManager;
    public class JTPCListUI extends BasicListUI{
      public void installUI(JComponent c){
        super.installUI(c);
        if(c instanceof JList){
          JList listJtpc = (JList)c;
          listJtpc.setCellRenderer(new JTPCListCellRenderer());
      public static ComponentUI createUI(JComponent c) {
        return new JTPCListUI();
      LineBorder m_borderSelected     = new LineBorder (Color.GREEN ,3);
      EmptyBorder m_borderDeselected  = new EmptyBorder(new Insets(3, 3, 3, 3));
       * COPY PASTE CODE FROM PARENT 'BasicListUI' ,IN JAVA VERSION  jdk1.6.0_18
       * Paint one List cell: compute the relevant state, get the "rubber stamp"
       * cell renderer component, and then use the CellRendererPane to paint it.
       * Subclasses may want to override this method rather than paint().
       * @see #paint
      protected void paintCell(
          Graphics g,
          int row,
          Rectangle rowBounds,
          ListCellRenderer cellRenderer,
          ListModel dataModel,
          ListSelectionModel selModel,
          int leadIndex)
        Object value = dataModel.getElementAt(row);
        boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
        boolean isSelected = selModel.isSelectedIndex(row);
        Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, row, isSelected, cellHasFocus);
        FocusBorderHandler h = new FocusBorderHandler();
        if(isSelected){
          ((JComponent)rendererComponent).setBorder(m_borderSelected);
        }else{
          ((JComponent)rendererComponent).setBorder(m_borderDeselected);
        int cx = rowBounds.x;
        int cy = rowBounds.y;
        int cw = rowBounds.width;
        int ch = rowBounds.height;
        boolean isFileList = Boolean.TRUE.equals(list.getClientProperty("List.isFileList"));
        if (isFileList) {
          // Shrink renderer to preferred size. This is mostly used on Windows
          // where selection is only shown around the file name, instead of
          // across the whole list cell.
          int w = Math.min(cw, rendererComponent.getPreferredSize().width + 4);
          if (!(list.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT)) {
            cx += (cw - w);
          cw = w;
        rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
      class JTPCListCellRenderer extends DefaultListCellRenderer {
        public  Component   getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
          setText(value.toString());
          return this;
    }Edited by: shay_te on 17:34 15/05/2010

Maybe you are looking for