diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-11-16 02:11:24 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-11-16 02:11:24 +0530 |
commit | ed3e023d1da3465bc79a91d38950a167004911b2 (patch) | |
tree | 08fb4de9af501612ccb85c8ee2f6beb60779c1f2 /src/UI/Components/BooksList.java |
Diffstat (limited to 'src/UI/Components/BooksList.java')
-rw-r--r-- | src/UI/Components/BooksList.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/UI/Components/BooksList.java b/src/UI/Components/BooksList.java new file mode 100644 index 0000000..05a2f5f --- /dev/null +++ b/src/UI/Components/BooksList.java @@ -0,0 +1,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(); + } +} |