I tried to make slideshow - images should be showed as the background of the window, so when I am large the window it should be resized. At the start images have right original size, but when I am enlarging the window, images doesn't change their size, there still have original size. I'd like to get it using class which extends JFrame, beucase I made attempt using JPanel - then images was resizeable, but each next image didn't adjust to the original size of the image (e.g. if the image have size 400x500px then frame should have that size but when I enlarge the window manually, it should become larger). Could anyone tell me why I can't resize that images? My window in situation when I changed its' size manually
public class Browser extends JFrame
{
private JLabel label;
private final File dir;
private int period, size;
private ImageIcon img;
private boolean end = false;
private int n = 0;
private File[] files;
private String m1 = "Koniec prezentacji", m2 = "Brak obrazka";
public Browser(String[] args)
{
panel = new JPanel();
setLayout(new BorderLayout());
dir = new File(args[0]);
period = Integer.parseInt(args[1]) * 1000;
size = Integer.parseInt(args[2]);
files = dir.listFiles();
Timer timer = new Timer(period, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (n < files.length)
{
setImage(files[n].getPath());
}
else
{
end = true;
JLabel l = new JLabel(m1, SwingConstants.CENTER);
setSize(200, 200);
setContentPane(l);
((Timer)e.getSource()).stop();
}
n++;
}
});
timer.start();
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(true);
setVisible(true);
}
public void setImage(String imgFileName)
{
img = new ImageIcon(imgFileName);
int w = img.getIconWidth();
int h = img.getIconHeight();
label = new JLabel(img);
if (w != -1 && w != 0 && h != -1 && h != 0)
{
setContentPane(label);
setSize(w, h);
}
else
{
JLabel l = new JLabel(m2, SwingConstants.CENTER);
setSize(200, 200);
setContentPane(l);
}
}
}