Re: efficiency of JList setElementAt()



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



Relevant Pages

  • Re: Preup F10->F11: Eclipse looses Java and SVN capabilities
    ... a Java app, all Java-related menu items apparently have returned. ... This time, neither eclipse ...     Take care ... Oliver Ruebenacker, Computational Cell Biologist ...
    (Fedora)
  • Re: Embedded java ?
    ... >I wonder if Cell ... A cellphone has very limited ram. ... desktop java, so you would have to study the available tools. ...
    (comp.lang.java.help)
  • Re: mutate an object or create a new one?
    ... intuitions about costs are wrong in the Java world. ... As a counterpoint to Chris's comments, note that Swing reuses objects in many cases, most notably renderers, for performance reasons. ... The table class defines a single cell renderer and uses it as a as a rubber-stamp for rendering all cells in the table; it renders the first cell, changes the contents of that cell renderer, shifts the origin to the new location, re-draws it, and so on. ...
    (comp.lang.java.programmer)
  • Preup F10->F11: Eclipse looses Java and SVN capabilities
    ... Now, when I open Eclipse, it seems to have lost all its ... Java and SVN capabilities. ... Oliver Ruebenacker, Computational Cell Biologist ...
    (Fedora)
  • Re: Colors for JTable cells
    ... You really need a textbook to hold your hand through JTables. ... * Returns the component used for drawing the cell. ... * used to configure the renderer appropriately before drawing. ... // corral dangerLevel into acceptable bounds. ...
    (comp.lang.java.gui)