14
14
import java .awt .event .ActionListener ;
15
15
import java .awt .event .MouseAdapter ;
16
16
import java .awt .event .MouseEvent ;
17
+ import java .awt .event .ComponentEvent ;
18
+ import java .awt .event .ComponentListener ;
17
19
import java .util .List ;
20
+ import javax .swing .BoxLayout ;
18
21
import javax .swing .JButton ;
19
22
import javax .swing .JFrame ;
20
23
import javax .swing .JLabel ;
@@ -32,7 +35,7 @@ public class CourseListWindow extends JPanel {
32
35
private static JFrame frame ;
33
36
private final JList <CourseCard > courses ;
34
37
private PreferencesPanel prefPanel ;
35
- private final JButton button ;
38
+ private static JButton button ;
36
39
37
40
public CourseListWindow (List <Course > courses , PreferencesPanel prefPanel ) {
38
41
this .prefPanel = prefPanel ;
@@ -42,9 +45,9 @@ public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
42
45
}
43
46
this .courses = new JList <>(courseCards );
44
47
this .courses .setSelectionMode (ListSelectionModel .SINGLE_SELECTION );
45
- setLayout (new BorderLayout ( ));
48
+ setLayout (new BoxLayout ( this , BoxLayout . Y_AXIS ));
46
49
this .button = new JButton ("Select" );
47
- this . button .addActionListener (new SelectCourseListener (this ));
50
+ button .addActionListener (new SelectCourseListener (this ));
48
51
49
52
this .courses .setCellRenderer (new CourseCellRenderer ());
50
53
this .courses .setVisibleRowCount (4 );
@@ -64,8 +67,8 @@ public void mouseClicked(MouseEvent event) {
64
67
}
65
68
}
66
69
});
67
- add (pane , BorderLayout . NORTH );
68
- add (this . button , BorderLayout . SOUTH );
70
+ add (pane );
71
+ add (button );
69
72
}
70
73
71
74
public static void display (PreferencesPanel prefPanel ) throws Exception {
@@ -75,12 +78,34 @@ public static void display(PreferencesPanel prefPanel) throws Exception {
75
78
frame .setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
76
79
List <Course > courses = prefPanel .getAvailableCourses ();
77
80
CourseDb .getInstance ().setAvailableCourses (courses );
78
- frame .setContentPane (new CourseListWindow (courses , prefPanel ));
81
+ final CourseListWindow courseListWindow = new CourseListWindow (courses , prefPanel );
82
+ frame .setContentPane (courseListWindow );
79
83
if (hasCourses (courses , prefPanel )) {
80
84
frame .pack ();
81
85
frame .setLocationRelativeTo (null );
82
86
frame .setVisible (true );
83
87
}
88
+ button .setMinimumSize (new Dimension (courseListWindow .getWidth (), button .getHeight ()));
89
+ button .setMaximumSize (new Dimension (courseListWindow .getWidth (), button .getHeight ()));
90
+ courseListWindow .addComponentListener (new ComponentListener () {
91
+ @ Override
92
+ public void componentResized (ComponentEvent event ) {
93
+ button .setMinimumSize (new Dimension (courseListWindow .getWidth (), button .getHeight ()));
94
+ button .setMaximumSize (new Dimension (courseListWindow .getWidth (), button .getHeight ()));
95
+ }
96
+
97
+ @ Override
98
+ public void componentMoved (ComponentEvent e ) {
99
+ }
100
+
101
+ @ Override
102
+ public void componentShown (ComponentEvent e ) {
103
+ }
104
+
105
+ @ Override
106
+ public void componentHidden (ComponentEvent e ) {
107
+ }
108
+ });
84
109
}
85
110
86
111
public static boolean isWindowVisible () {
0 commit comments