How can I display a Sequence in a GUI

When building a bioinformatics GUI you will probably want to display the sequence of residues in the Sequence you are displaying. BioJava contains a number of GUI components that can render various aspects of a Sequence.

The basic unit of any Sequence based GUI is the SequenceRenderContext which holds the Sequence and sends instructions to a SequenceRenderer which does the actual drawing of the Sequence. There are several SequenceRenderer implementations in BioJava. The one to display the order of residues is the SymbolSequenceRenderer.

The following program demonstrates the use of a SequenceRenderContext and a SequenceRenderer to display the symbols in a Sequence.

[frame center A screen shot of the GUI](image:Seqview.jpg “wikilink”)

```java import java.awt.*; import java.awt.event.*;

import javax.swing.*;

import*; import*; import*;

public class SeqView extends JFrame {

 private Sequence seq;
 private JPanel jPanel = new JPanel();
 private SequencePanel seqPanel = new SequencePanel();
 private SequenceRenderer symSeqRenderer = new SymbolSequenceRenderer();

 public SeqView() {
   try {
     //create the sequence to display
     seq = RNATools.createRNASequence("accggcgcgagauuugcagcgcgcgcgcaucgcg"+
   catch(Exception e) {

 public static void main(String[] args) {
   SeqView seqView = new SeqView();

  * Set up the components to display the graphics
 private void init() throws Exception {
   this.getContentPane().setLayout(new BorderLayout());
   this.getContentPane().add(jPanel, BorderLayout.CENTER);
   jPanel.add(seqPanel, BorderLayout.CENTER);

   //set the sequence to display

   //set the object responsible for painting the sequence

   //the amount of sequence to display
   seqPanel.setRange(new RangeLocation(1,seq.length()));

  * Overide this to close the program when the window closes.
 protected void processWindowEvent(WindowEvent we){
   if (we.getID() == WindowEvent.WINDOW_CLOSING) {
   else {

} ```