I have the following code :
public class TryToMakeSomethingHappen extends JPanel {
private JFrame f;
private JPanel p;
public TryToMakeSomethingHappen() {
f=new JFrame("Title");
f.setSize(600, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p=new JPanel(new BorderLayout());
ImageIcon ic=new ImageIcon("/home/michael/Pictures/begin1.jpg");
int imageHeight = ic.getIconHeight();
int imageWidth = ic.getIconWidth();
BufferedImage bimg = new BufferedImage(imageWidth ,imageHeight, BufferedImage.TYPE_INT_ARGB);
int pixels[][]=new int[imageWidth][imageHeight];
for (int i=0;i<imageWidth;i++)
for(int j=0; j<imageHeight;j++)
pixels[i][j]=bimg.getRGB(i, j);
BufferedImage bimg2=new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
for(int y=0;y<imageHeight;y++)
for(int x=0;x<imageWidth;x++){
bimg2.setRGB(x, y,pixels[x][y]);
}
File file= new File("/home/michael/Pictures/pic2.png");
JLabel label=new JLabel("",ic,JLabel.CENTER);
JLabel label1;
try {
ImageIO.write(bimg2,"PNG",file);
ImageIcon ic2=new ImageIcon("/home/michael/Pictures/pic2.png");
label1=new JLabel("",ic2,JLabel.CENTER);
p.add(label1,BorderLayout.EAST);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.add(label,BorderLayout.WEST);
f.setVisible(true);
f.add(p);
}
public static void main(String[]args){
TryToMakeSomethingHappen t = new TryToMakeSomethingHappen();
}
}
f is JFrame, bimg2 is BufferedImage and ,p is JPanel. (privates of my class).
The WEST picture is showing while EAST picture is not. Why is that? When i check pic2 in the folder, it is empty. I use Linux (Ubuntu).
How do I make bimg2 to show on the EAST side of the panel?