Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #780
| From | "Ooder" <ooder@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: JList items |
| Message-ID | <1169588902.383240.80850@q2g2000cwa.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <ep5srj$uv0$1@registered.motzarella.org> |
| Date | 2011-04-27 15:29 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Awesome, I'll give that a try. Thanks
Michael Rauscher wrote:
> 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
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Find similar | Unroll thread
JList items "Ooder" <ooder@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
Re: JList items "Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
Re: JList items "Ooder" <ooder@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
csiph-web