0
特定の日付に利用可能なタイムスロットを見つけて表示するボタンがあります。しかし、これを複数回実行すると、タイムスロットの量が以前の結果よりも少ない場合、以前のJLabelを削除できません。余分なJLabelがRemoveAll()の後にフレームから削除されない
毎回これらの余分なラベルを削除するにはどうすればよいですか?
ありがとうございました!フレームを塗り替え
timeCheck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
farRightSidePanel.removeAll();
String selectedDoctor = doctorsDropdown.getSelectedItem().toString();
List<String> times = new ArrayList<String>(Arrays.asList(allAppointmentTimes));
List<String> takenAppointmentTimes = db.freeTimeslotsDB(
datePicker.getJFormattedTextField().getText(),
selectedDoctor.substring(selectedDoctor.length() - 2));
times.removeIf(t -> takenAppointmentTimes.contains(t));
for (String time : times) {
farRightSidePanel.add(new JLabel(time));
farRightSidePanel.revalidate();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}