Just finishing a program that has a jpg in the background (large pic) and needs a scrollbar and that i can draw on the top by making lines. I can get it to draw the lines and have no picture. I can get a picture and no lines will draw or I can have a picture and make lines and have no scrollbar! Just can't have it all at once. What am i doin wrong here?
Key points...
class
Testing extends JFrame
{
Image img;
ImageIcon picture;
JLabel labelPic;
JMenuItem newMap;
JMenuItem openMap;
JMenuItem exitMap;
JMenuItem eraseLastLine;
JMenuItem searchTrackNum;
ArrayList<Shape> shapes=new ArrayList<Shape>();
public Testing()
{
blah blah
JPanel p = new JPanel();
ImageIcon picture=new ImageIcon("c:\\programing\\javaclasses\\Trackbuilder\\9998.jpg");
JLabel labelPic=new JLabel(picture);
p.add(labelPic);
img=picture.getImage();
this.add(new PaintSurface()); //test
p.setPreferredSize(new Dimension(5000,5000));
int height;
height=picture.getIconHeight();
int width;
width=picture.getIconWidth();
p.setPreferredSize(new Dimension(width,height));
JScrollPane sp = new JScrollPane (p);
getContentPane().add(sp); // lose scroll if i disable this but can draw and have a pic
}
paint class here ...
public void paint(Graphics g)
{
g.drawImage(img,0,0,this); // this makes the pic appear
Graphics2D g2=(Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color[] colors={Color.RED, Color.BLUE, Color.PINK, Color.YELLOW, Color.CYAN};
int colorIndex=0;
g2.setStroke(new BasicStroke(2));
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f));
for (Shape s:shapes)
{
g2.setPaint(Color.BLACK);
g2.draw(s);
}
if(startDrag !=null && endDrag !=null)
{
g2.setPaint(Color.LIGHT_GRAY);
Shape r=new Line2D.Float(startDrag.x, startDrag.y, endDrag.x, endDrag.y);
g2.draw(r);
}
}
thanks in advance..
roba