Swing JDatePicker

skrobi

Mitglied
Hallo,

ich benötige ein Java-Programm das in einem Feld ein Datum in der Form TT.MM.JHJJ anzeigt. Beim Anklicken des Feldes wird ein Kalender geöffnet, in dem ein gewünschtes Datum durch Anklicken ausgewählt und in das ursprüngliche Datumsfeld übertragen wird.

Unter „www.java-forum.org/thema/codebeispiel-fuer-jdatepicker.166422/“ wurde ich fündig und kopierte mir JDatePicker 1:1 auf mein Notebook. Mittels Java JDK 17-0-1 und Eclipse IDE 2021-09 (4.21.0) werden folgende Fehler angezeigt:

(*) import org.jdatepicker.JDateComponentFactory;
(*) import org.jdatepicker.JDatePanel;
(*) import org.jdatepicker.JDatePicker;
(*) Fehlerhinweis: The import org.jdatenpicker cannot be resolved

(*) JDateComponentFactory factory = new JDateComponentFactory();
(*) Fehlerhinweis: Multiple markers at this line

(*) JDatePanel datePanel = factory.createJDatePanel();
datePanel.addActionListener(e -> {
System.out.println(datePanel.getModel().getValue());
});
(*) Fehlerhinweis: JDatePanel cannot be resolved to a type

(*) JDatePicker datePicker = factory.createJDatePicker();
datePicker.addActionListener(e -> {
System.out.println(datePicker.getModel().getValue());
});
(*) Fehlerhinweis: JDatePicker cannot be resolved to a type

Möglicherweise fehlen Bibliothek, Definitionen, Dateien, etc. Vielleicht kann mit jemand mitteilen,
was – wie – wo ich machen muss, damit das Programm läuft.

Vielen Dank im Voraus

skrobi
 

comp_math

Mitglied
Ich habe ein Problem mit JDatePicker: Ich möchte die Daten, die früher als heute sind, nicht wählbar machen? Hat jemand eine Idee?
Picker.JPG
 

Anhänge

  • DatePicker.java
    1 KB · Aufrufe: 2

Neumi5694

Top Contributor
Beim Picket ist per Default nichts gesperrt.
Die Ursache dürfte in factory.createJDatePicker() zu finden sein.

ps: Poste Quelltext und keine Screenshots.
Verwende die Code-Tags dafür

So ist nichts gesperrt.
Java:
    public static void main(String[] args) {
        var frame = new JFrame();
        var picker = new JDatePicker();
        frame.setContentPane(picker);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
 

comp_math

Mitglied
Java:
    public List<Protocol> searchInProtocolsInDBAsList(LocalDate meetingDate, LocalDate resubmissionDate, LocalDate deleteDate,
                                                String wordTopic, String wordRemark) throws SQLException {

        List<Protocol> myList = new ArrayList<>();

        String sql = "SELECT pe.protocol_id, pe.protocol_entry_id FROM protocol p, protocolentry pe " +
                "WHERE pe.protocol_id=p.protocol_id " +
                "AND topic ilike ? " +
                "AND remark ilike ? " +
                "AND (meeting_date = COALESCE(?, meeting_date)) " +
                "AND (COALESCE(resubmission_date,'9999-12-30') < COALESCE(?, resubmission_date + 1, '9999-12-31')) " +
                "AND (COALESCE(delete_date, '9999-12-30') < COALESCE(?, delete_date + 1, '9999-12-31')) " +
                "ORDER BY meeting_date, delete_date DESC";

        try (PreparedStatement statement = DB_Connection.getStatement().getConnection().prepareStatement(sql)) {

            statement.setString(1,  (null != wordTopic ? ("%" + wordTopic.trim() + "%") : "%%" ));
            statement.setString(2, (null != wordRemark ? ("%" + wordRemark.trim() + "%") : "%%" ));
            statement.setDate(3, getValidDate(meetingDate));
            statement.setDate(4, getValidDate(resubmissionDate));
            statement.setDate(5, getValidDate(deleteDate));

            ResultSet rs = statement.executeQuery();

            while (rs.next()) {
                Protocol protocol = getProtocol(rs.getInt(1), false);
                ProtocolEntry protocolEntry = getProtocolEntry(rs.getInt(2));

                boolean found = false;
                for (Protocol p : myList) {
                    if (p.equals(protocol)) {
                        p.addEntry(protocolEntry);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    myList.add(protocol);
                    protocol.addEntry(protocolEntry);
                }
            }
        }
        return myList;
    }
 

Ähnliche Java Themen

Neue Themen


Oben