aboutsummaryrefslogtreecommitdiff
path: root/src/UI/Components/BooksList.java
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:16:16 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:16:16 +0530
commitda6b366397aa15e2686840c1d9ffa5dae5d49d2a (patch)
treea53bc42092a564bfbf66a67b70e3aa9cb8689798 /src/UI/Components/BooksList.java
First Commit
Diffstat (limited to 'src/UI/Components/BooksList.java')
-rw-r--r--src/UI/Components/BooksList.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/UI/Components/BooksList.java b/src/UI/Components/BooksList.java
new file mode 100644
index 0000000..dfb21bf
--- /dev/null
+++ b/src/UI/Components/BooksList.java
@@ -0,0 +1,47 @@
+package UI.Components;
+
+import Store.Book;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+public class BooksList extends JPanel {
+ private static JPanel listPanel;
+
+ public BooksList() throws SQLException {
+ listPanel = new JPanel();
+ listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
+
+ refreshBooks();
+
+ JScrollPane scrollPane = new JScrollPane(listPanel);
+ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+
+ this.add(scrollPane);
+
+ this.setBorder(new EmptyBorder(4, 8, 8, 8));
+ this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ }
+
+ public static void refreshBooks(ArrayList<Book> books) throws SQLException {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ listPanel.removeAll();
+
+ for (Book book : books) {
+ listPanel.add(new BookListItem(book));
+ }
+
+ listPanel.revalidate();
+ listPanel.repaint();
+ }
+ }).start();
+ }
+
+ public static void refreshBooks() throws SQLException {
+ refreshBooks(Book.getAll(false));
+ }
+}