i'm working on a java app for my school project. I need to display a list of "cards" in a container. If the number of card exced 3, the following cards will no be visible due to the size of the container : The list of cards in question:
So I'm trying to use a JScrollPane because it seems to be the solution. But I don't succed to make the Panel scrollable. Any idea ?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class FenetrePrincipale extends JFrame implements ActionListener,MouseListener{
LinkedList<Carte> cartesFidelite; //Liste des cartes de fidélités
JPanel conteneurCarte;
JPanel monConteneurMain;
JScrollPane scrollPane;
public FenetrePrincipale(LinkedList<Carte> c){
cartesFidelite=c; //List of cards
//Window
setTitle("Gestionnaire de cartes");
setBounds(0, 0, 1195,722);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
//CONTAINER Main
containerMain = new JPanel();
containerMain.setLayout(null);
containerMain.setBackground(Color.white);
//CONTAINER List of cards
conteneurCarte = new JPanel();
conteneurCarte.setLayout(null);
conteneurCarte.setBackground(new Color(242,242,242));
conteneurCarte.setBorder(BorderFactory.createLineBorder(new Color(199,199,199)));
scrollPane = new JScrollPane(conteneurCarte);
scrollPane.setBounds(34, 90, 377,550);
containerMain.add(scrollPane);
here is the method which display cards :
public void refreshListCard (){
conteneurCarte.removeAll();
int i = 0;
for(Carte e : cartesFidelite){
e.setLocation(15,(15+i*(172+15)));
conteneurCarte.add(e);
e.addMouseListener(this);
i++;
}
conteneurCarte.updateUI();
}
Thanks for your help :)