2016-05-24 5 views
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(); 
       } 
      } 

All available appointments

Problem with labels 2 appointments unavailable

答えて

0

問題を修正しているようです。

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(); 
         farRightSidePanel.repaint(); 
        } 

       } catch (SQLException e1) { 

        e1.printStackTrace(); 
       } 
      } 
関連する問題