From 18bd90b3621344534a7df18f7831514615cd68d6 Mon Sep 17 00:00:00 2001 From: js Date: Fri, 3 Apr 2020 14:03:40 +0200 Subject: [PATCH] added support for displaying list of files but need scrollbar --- src/gui/MainWindow.java | 4 +++- src/gui/downloadSelection.java | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/gui/downloadSelection.java diff --git a/src/gui/MainWindow.java b/src/gui/MainWindow.java index 42bcc0b..4bd2a07 100644 --- a/src/gui/MainWindow.java +++ b/src/gui/MainWindow.java @@ -10,7 +10,9 @@ public class MainWindow extends JFrame{ fenetre.setSize(550, 200); fenetre.setLocationRelativeTo(null); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - fenetre.add(new Parameters()); + //fenetre.add(new Parameters()); + String[] listTest = {"test", "test2", "test3", "test4", "test5", "test6", "test7"}; + fenetre.add(new downloadSelection(listTest)); fenetre.setVisible(true); } diff --git a/src/gui/downloadSelection.java b/src/gui/downloadSelection.java new file mode 100644 index 0000000..2fb4dba --- /dev/null +++ b/src/gui/downloadSelection.java @@ -0,0 +1,43 @@ +package gui; + +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JButton; +import javax.swing.JTextField; +import javax.swing.JComboBox; +import javax.swing.JList; +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.GridLayout; + +public class downloadSelection extends JPanel { + + private String[] listFilesToDownload; + private JList list1; + private JLabel label1; + private JButton downloadButton; + + public downloadSelection(String[] listFilesToDownload){ + JPanel p1 = new JPanel(); + JPanel p2 = new JPanel(); + JPanel p3 = new JPanel(); + FlowLayout layout = new FlowLayout(); + this.listFilesToDownload = listFilesToDownload; + this.list1 = new JList<>(listFilesToDownload); + this.label1 = new JLabel("List of files you can download: "); + this.downloadButton = new JButton("download"); + this.list1.setSelectedIndex(0); + p1.setLayout(layout); + p2.setLayout(layout); + p3.setLayout(layout); + this.setLayout(new GridLayout(3, 1)); + p1.add(label1); + p2.add(list1); + p3.add(downloadButton); + this.add(p1, BorderLayout.NORTH); + this.add(p2, BorderLayout.CENTER); + this.add(p3, BorderLayout.SOUTH); + setVisible(true); + } + +}