I have a JPanel in a JScrollPane. After the Panel and the ScrollPane are created I fill the Panel with JButtons. But I don't get the ScrollPane to work. It just won't scroll my Panel.
Maybe it's something very easy but I'm not this experienced in GUI programming. I've already searched and tried some things I found out there... but I didn't get my GUI to work.
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.CardLayout;
import java.util.ArrayList;
import javax.swing.JLabel;
public class GUI extends JFrame {
private Container pinnwand;
private JPanel Team = new JPanel();
private JPanel MonsterListe = new JPanel();
private JScrollPane cntAvailableMonster = new JScrollPane();
private ArrayList<JLabel> AvailableMonstersLabels = new ArrayList<JLabel>();
public GUI() {
this.pinnwand = getContentPane();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 530, 443);
this.pinnwand.setLayout(new CardLayout(0,0));
this.Team.setBackground(new Color(44,44,44));
this.Team.setLayout(null);
this.MonsterListe.setMinimumSize(new Dimension(200,400));
this.cntAvailableMonster.setBounds(300, 0, 200, 400);
this.cntAvailableMonster.setPreferredSize(new Dimension(200,1000));
this.cntAvailableMonster.createVerticalScrollBar();
this.cntAvailableMonster.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.cntAvailableMonster.setViewportView(this.MonsterListe);
this.MonsterListe.setLayout(null);
this.Team.add(this.cntAvailableMonster);
this.pinnwand.add(this.Team,"Team");
this.setAvailableMonsters();
}
private void setAvailableMonsters() {
for(int i = 0,amount = 20;i < amount;i++) {
this.AvailableMonstersLabels.add(new JLabel("monster"+i));
this.AvailableMonstersLabels.get(i).setBounds(0, i*30, 300, 30);
this.AvailableMonstersLabels.get(i).setBackground(new Color(255,0,0));
this.AvailableMonstersLabels.get(i).setOpaque(true);
this.MonsterListe.add(this.AvailableMonstersLabels.get(i));
this.MonsterListe.setBackground(new Color(0,0,0));
}
}
public static void main(String[] args) {
new GUI().setVisible(true);
}
}
Thanks in advance :)