[Biojava-l] Cast to Sequence

mark.schreiber at novartis.com mark.schreiber at novartis.com
Sun Jul 31 21:41:05 EDT 2005


You might also want to use the Biojava FeatureTree class. An example of 
it's use is at http://www.biojava.org/docs/bj_in_anger/treeView.htm

- Mark





Jacob Rohde <rohdester at gmail.com>
Sent by: biojava-l-bounces at portal.open-bio.org
07/31/2005 08:36 PM
Please respond to Jacob Rohde

 
        To:     biojava-l at biojava.org
        cc:     (bcc: Mark Schreiber/GP/Novartis)
        Subject:        [Biojava-l] Cast to Sequence


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

_______________________________________________
Biojava-l mailing list  -  Biojava-l at biojava.org
http://biojava.org/mailman/listinfo/biojava-l





More information about the Biojava-l mailing list