So i've been trying this for some time now and can't seem to be able to make it work.
Ok so i'm making a catalog in netbeans and working with Java. I dragged in a JPanel from the palettes window and named it "panel". The only problem is I can't make the panel scroll vertically.
I was reading up some questions here and searching in the web and found that I can use JScrollPane
in Java the only problem is whenever i try to use this, the panel seems to disappear, and when I don't add it, it works fine, the problem is all of my other elements overflow off the panel.
So here's the code i'm using:
initComponents();
//Just adding some elements in the panel
for(int i = 1; i <= 10; i++){
//Position elements in a new line so they won't overflow to the right
if(counter == 7){
locationTop += 350;
locationLeft = 90;
locationTopViewMore += 350;
locationTopAgregar += 550;
counter = 0;
}
//Adding an image and a couple of buttons
JLabel myLabel= new JLabel();
myLabel.setIcon(new ImageIcon("" + save)); //Adding an image
myLabel.setSize(200, 200);
myLabel.setLocation(locationLeft, locationTop);
panel.add(myLabel);
JButton btnViewMore = new JButton("View More"); //Making a button.
btnViewMore.setSize(100, 50);
btnViewMore.setLocation(locationLeft + 50, locationTopViewMore);
panel.add(btnViewMore);
JButton btnAgregar = new JButton("Another Button"); //Making another button.
btnAgregar.setSize(150, 50);
btnAgregar.setLocation(locationLeft + 25, locationTopAgregar);
panel.add(btnAdd);
locationLeft += 200;
counter++;
}
//JScrollPane scrollPane = new JScrollPane(panel);
So this is what happens when i don't use the JScrollPane
:
http://i57.tinypic.com/acel3s.png
And this is what happens when i do use the JScrollPane
:
http://i57.tinypic.com/2ltlcwj.png
Any help is greatly appreciated. Thanks!