Re: efficiency of JList setElementAt()
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Tue, 20 Dec 2005 05:08:24 GMT
On Tue, 20 Dec 2005 00:58:50 GMT, "Raymond Cruz" <nospam@xxxxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :
>So I have a new question -- is there a way to produce different font colors
>that is much more efficient than using HTML strings in Java?
For JTree you write customCellRenderers. That should be many times
faster than using HTML. Presumably there is a similar feature for
your component.
The key is a method something like this:
/**
* Returns the component used for drawing the cell. This method
is
* used to configure the renderer appropriately before drawing.
* Associated TableModel must implement DangerTableModel.
*
* @param table the <code>JTable</code> that is asking
the
* renderer to draw; can be
<code>null</code>
* @param value the value of the cell to be rendered.
It is
* up to the specific renderer to
interpret
* and draw the value. For example, if
* <code>value</code>
* is the string "true", it could be
rendered as a
* string or it could be rendered as a
check
* box that is checked. <code>null</code>
is a
* valid value
* @param isSelected true if the cell is to be rendered
with the
* selection highlighted; otherwise false
* @param hasFocus if true, render cell appropriately.
For
* example, put a special border on the
cell, if
* the cell can be edited, render in the
color used
* to indicate editing
* @param row the row index of the cell being drawn.
When
* drawing the header, the value of
* <code>row</code> is -1
* @param column the column index of the cell being
drawn
*/
public Component getTableCellRendererComponent( JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
Component cell = super.getTableCellRendererComponent( table,
value,
isSelected,
hasFocus,
row,
column);
int dangerLevel =
((DangerTableModel)(table.getModel())).getDangerLevel( row );
// normal
cell.setForeground( winAttrScheme.getForeground( dangerLevel )
);
cell.setBackground( winAttrScheme.getBackground( dangerLevel )
);
cell.setFont( winAttrScheme.getFont ( dangerLevel ) );
return cell;
}
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- References:
- efficiency of JList setElementAt()
- From: Raymond Cruz
- Re: efficiency of JList setElementAt()
- From: Thomas Hawtin
- Re: efficiency of JList setElementAt()
- From: Raymond Cruz
- Re: efficiency of JList setElementAt()
- From: Thomas Hawtin
- Re: efficiency of JList setElementAt()
- From: Raymond Cruz
- efficiency of JList setElementAt()
- Prev by Date: Re: efficiency of JList setElementAt()
- Next by Date: Re: Event Handling and Maintainability
- Previous by thread: Re: efficiency of JList setElementAt()
- Next by thread: Re: efficiency of JList setElementAt()
- Index(es):
Relevant Pages
|