Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #777 > unrolled thread

JList items

Started by"Ooder" <ooder@THRWHITE.remove-dii-this>
First post2011-04-27 15:29 +0000
Last post2011-04-27 15:29 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  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

#777 — JList items

From"Ooder" <ooder@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
SubjectJList items
Message-ID<1169573019.407108.250060@a75g2000cwd.googlegroups.com>
  To: comp.lang.java.gui
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?

Thanks

---
 * 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

[toc] | [next] | [standalone]


#779

From"Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
Message-ID<ep5srj$uv0$1@registered.motzarella.org>
In reply to#777
  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

[toc] | [prev] | [next] | [standalone]


#780

From"Ooder" <ooder@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
Message-ID<1169588902.383240.80850@q2g2000cwa.googlegroups.com>
In reply to#779
  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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web