S
Shuaib
I have been trying to solve this problem for some time but haven't
found a solution yet.
Here is what I wanna do: A scrollable JPanel having GridLayout to
which I add images of any size which are also in JPanel(s). The image
size should be maintained and when I need to see the part not visible
in the screen I can use the scrollbar.
Here is the simplified form of what I am currently doing:
JPanel p = new JPanel();
JScrollPane sp = new JScrollPane(p);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
p.setLayout(new GridLayout(1,2));
JPanel p1 = new JPanel();
ImageIcon icon1 = new ImageIcon(url1);
JLabel image1 = new JLabel(icon1);
p1.add(image1, BorderLayout.CENTER);
p.add(p1);
JPanel p2 = new JPanel();
ImageIcon icon2 = new ImageIcon(url2);
JLabel image2 = new JLabel(icon2);
p2.add(image2, BorderLayout.CENTER);
p.add(p2);
For single image, it does appear in the panel but its top and bottom
are chopped off if it is in portrait orientation with no vertical
scrollbar. For two images, it tries to fit both by chopping them off
from the sides too. Both appear together in the viewport without
horizontal and vertical scrollbars.
Any help will be highly appreciated.
-SA
found a solution yet.
Here is what I wanna do: A scrollable JPanel having GridLayout to
which I add images of any size which are also in JPanel(s). The image
size should be maintained and when I need to see the part not visible
in the screen I can use the scrollbar.
Here is the simplified form of what I am currently doing:
JPanel p = new JPanel();
JScrollPane sp = new JScrollPane(p);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
p.setLayout(new GridLayout(1,2));
JPanel p1 = new JPanel();
ImageIcon icon1 = new ImageIcon(url1);
JLabel image1 = new JLabel(icon1);
p1.add(image1, BorderLayout.CENTER);
p.add(p1);
JPanel p2 = new JPanel();
ImageIcon icon2 = new ImageIcon(url2);
JLabel image2 = new JLabel(icon2);
p2.add(image2, BorderLayout.CENTER);
p.add(p2);
For single image, it does appear in the panel but its top and bottom
are chopped off if it is in portrait orientation with no vertical
scrollbar. For two images, it tries to fit both by chopping them off
from the sides too. Both appear together in the viewport without
horizontal and vertical scrollbars.
Any help will be highly appreciated.
-SA