Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Michael Rauscher" Subject: Re: JList items Message-ID: X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: <1169573019.407108.250060@a75g2000cwd.googlegroups.com> References: <1169573019.407108.250060@a75g2000cwd.googlegroups.com> Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 55 Date: Wed, 27 Apr 2011 15:29:30 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918170 96.60.20.240 (Wed, 27 Apr 2011 10:29:30 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:29:30 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:779 To: comp.lang.java.gui Ooder schrieb: > Hi, > > I have a JList that contains a list of steps to do something. When the > user completes a step they then select the next step, and the previous > step is considered complete. Is there a way to format an individual > JList item, so I could visually display that a step is done (italic > text, unenabled, gray background, etc)? Do I have to create a custom > ListCellRenderer? If so, how, since I need to be able to customize > individual items in the list? One possibility would be to not use JList but JTable having two columns for both, the step and the status of the task. If you want to use JList, then you would have to use a custom cell renderer. The "how to" is something that you must decide on your own. In general, a cell renderer performs only the... rendering :) Therefore the status of a task is not stored by the renderer but is represented by the value it should render. Depending on what you currently have you'll need a class that represents a task and the task's status: class TaskEntry { private String title; private boolean done; ... } The ListModel returns objects of type TaskEntry. The cell renderer handles them, e. g. class TaskEntryRenderer extends DefaultListCellRenderer { private Color OUTSTANDING = Color.BLACK; private Color DONE = Color.GREEN; public Component getListCellRendererComponent( JList list, Object value, int index, boolean sel, boolean focus ) { TaskEntry entry = (TaskEntry)value; Component c = super.getListCellRendererComponent( list, entry.getTitle(), index, sel, focus ); c.setColor( entry.isDone() ? DONE : OUTSTANDING ); return c; } } Bye Michael --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24