I am making program which will show zoomed in picture in scrolled frame and allow user to change single pixels of buffered image. I am trying to add panel with buffered image to scrolledPane but scroll bars wont appear. Here is my panel:
package biometria1;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class noobPanel extends JPanel implements MouseListener{
private BufferedImage background;
int scale = 8;
noobPanel self;
public noobPanel(File file){
self = this;
try {
background = ImageIO.read(file);
} catch (IOException ex) {
Logger.getLogger(noobPanel.class.getName()).log(Level.SEVERE, null, ex);
}
addMouseListener(this);
}
public BufferedImage getImage(){
return this.background;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(background, 0, 0, background.getWidth()*8, background.getHeight()*8, 0, 0, background.getWidth(), background.getHeight(), this);
}
@Override
public void mouseClicked(MouseEvent e) {
int x = e.getX()/scale;
int y = e.getY()/scale;
System.out.println("before:"+background.getRGB(x, y));
background.setRGB(x, y, 100);
System.out.println("after:"+background.getRGB(x, y));
self.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseEntered(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseExited(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
and thats how i add this panel in frame:
File image = chooser.getSelectedFile();
obraz = new noobPanel(image);
scrollPanel= new JScrollPane(obraz);
// 8 because i scale its 8 times bigger
obraz.setPreferredSize(new Dimension(obraz.getWidth()*8, obraz.getHeight()*8));
self.setSize(860, 640);
self.add(scrollPanel);
self.pack();
self.revalidate();
self.repaint();
Could u tell me what I am doing wrong? Thanks for any advice