I have redone a few things and decided to change up the way the panel I was having problems with was displayed. Now it pops up in a new JFrame, but I am having problems here as well. The graphics aren't displaying quite correctly and when I resize it everything disappears. Here is the code:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.border.*;
import java.awt.event.*;
public class seqDisplayFrame extends JFrame
{
private interactiveRectangle iRect;
private seqDisplayFrame sdFrame;
public seqDisplayFrame(interactiveRectangle iR)
{
sdFrame = this;
iRect = iR;
sdFrame.setTitle(iRect.getContigName());
seqDisplayPanel sdPanel = new seqDisplayPanel(iRect);
sdFrame.add(sdPanel);
sdFrame.pack();
}
private class seqDisplayPanel extends JPanel
{
private interactiveRectangle intRect;
private int paintY = 20;
public seqDisplayPanel(interactiveRectangle iR)
{
intRect = iR;
setPreferredSize(new Dimension(500,500));
setBackground(Color.WHITE);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
String tempString = intRect.getContigSeq();
int xDistance = 20;
for(int i = 0; i < tempString.length(); i++)
{
if(i < (intRect.getStartOfUsedRegion() -1) || i > (intRect.getEndOfUsedRegion()-1))
g2.setColor(Color.BLACK);
else
g2.setColor(Color.RED);
g2.drawString(String.valueOf(tempString.charAt(i)), xDistance, paintY);
xDistance += 8;
if(xDistance > 480)
{
xDistance = 20;
paintY += 15;
}
}
g2.setColor(Color.BLACK);
paintY +=20;
String totalLength = ("The total length is: " + String.valueOf(intRect.getTotalLength()));
g2.drawString(totalLength, 20, paintY);
}
}
}