[Biojava-l] Cast to Sequence
Jacob Rohde
rohdester at gmail.com
Sun Jul 31 08:36:36 EDT 2005
Hi,
I'm having a problem with a JTree and rendering of Sequences.
Since the JTree calls toString() on objects when displaying them, I
had to make my own TreeCellRenderer because the Sequence toString
method prints out debug info.
My code looks like this:
public class FeatureTreeCellRenderer extends DefaultTreeCellRenderer
{
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
{
JLabel l = (JLabel) super.getTreeCellRendererComponent(tree,
value, sel, expanded, leaf, row, hasFocus);
if(leaf)
{
System.out.println(value);
Sequence s = (Sequence) value;
l.setText(s.getName());
}
return l;
}
}
My problem is that I always get a ClassCastException. The weird thing
is that the println method call above the cast clearly shows that the
cast should be possible.
This is the output of the pint statement:
org.biojava.bio.seq.impl.SimpleSequence at 2ba11b name: DNA seq 0
And this is the exception:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
javax.swing.tree.DefaultMutableTreeNode
.
etc.
etc.
I'm so confused. Any ideas?
Thanks in advance,
Jacob Rohde
More information about the Biojava-l
mailing list