aboutsummaryrefslogtreecommitdiff
path: root/src/UI/Components/BooksList.java
blob: 05a2f5f5eb21663bc275a1d576f50db0cb536761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package UI.Components;

import Client.Book;

import javax.swing.*;
import java.util.ArrayList;

public class BooksList extends JPanel {
    private static JPanel listPanel;

    public BooksList() {
        listPanel = new JPanel();
        listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));

        JScrollPane scrollPane = new JScrollPane(listPanel);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        this.add(scrollPane);

        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    }

    public static void refreshBooks(ArrayList<Book> books) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                listPanel.removeAll();

                for (Book book : books) {
                    listPanel.add(new BookListItem(book));
                }

                listPanel.revalidate();
                listPanel.repaint();
            }
        }).start();
    }
}