0

This is my code, i have a combobox where choose user by chosen user query select dates from database and return dates this dates are highlights in jcalendar

Connect1();
if(txtdoc.getSelectedItem()==null){

       } else {
           SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        String fio1 = txtdoc.getSelectedItem().toString();
        String sql = "select distinct date from mesta where  seats = '"+fio1+"'";
        HighlightEvaluator evaluator = new HighlightEvaluator();
        try{
            pst = con1.prepareStatement(sql);
            rs = pst.executeQuery();
            Component com[] = txtd.getComponents();
            while (rs.next()){
               Date date6 = sdf.parse(rs.getString("date"));
               
                evaluator.add(date6);
                txtd.setCalendar(txtd.getCalendar());
                txtd.getDayChooser().addDateEvaluator(evaluator);
                
            }
        }
        catch(Exception e){}
       }
public static class HighlightEvaluator implements IDateEvaluator {
    private final List<Date> list = new ArrayList<>();
    public void add(Date date) {
        list.add(date);
    }

    public void remove(Date date) {
        list.remove(date);
    }

    public void setDates(List<Date> dates) {
        list.addAll(dates);
    }

    @Override
    public Color getInvalidBackroundColor() {
        return Color.BLACK;
    }

    @Override
    public Color getInvalidForegroundColor() {
        return null;
    }

    @Override
    public String getInvalidTooltip() {
        return null;
    }

    @Override
    public Color getSpecialBackroundColor() {
        return Color.GREEN;
    }

    @Override
    public Color getSpecialForegroundColor() {
        return Color.RED;
    }

    @Override
    public String getSpecialTooltip() {
        return "Приемный день";
    }

    @Override
    public boolean isInvalid(Date date) {
        return false;
    }

    @Override
    public boolean isSpecial(Date date) {
        return list.contains(date);
    }
}

highlight is working for me But when i change user and update ,old highlights are staying How remove old highlights?

i tried

txtd.getDayChooser().removeDateEvaluator(evaluator);

but its clear all highlights..

0 Answers0