0

I am trying to get a simple JDatePicker to work from clojure. Following these code snipets but with the intent of getting it to work from clojure through java interop. I can't even get started.

This is the java code:

UtilDateModel model = new UtilDateModel();
JDatePanelImpl datePanel = new JDatePanelImpl(model);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
frame.add(datePicker);

I can't even get passed the first part in clojure

user=> (import org.jdatepicker.JDatePicker)
org.jdatepicker.JDatePicker
user=> (UtilDateModel.)

CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: UtilDateModel, compiling:(/tmp/form-init7437510410318747099.clj:1:1) 
user=> 

I tried importing the class

user=> (import org.jdatepicker.JDatePicker.UtilDateModel)

ClassNotFoundException org.jdatepicker.JDatePicker.UtilDateModel  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> (import org.jdatepicker.UtilDateModel)

ClassNotFoundException org.jdatepicker.UtilDateModel  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> 

user=> (import '(org.jdatepicker.JDatePicker.UtilDateModel as um))

ClassNotFoundException org.jdatepicker.JDatePicker.UtilDateModel.as  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> (import '(org.jdatepicker.UtilDateModel as um))

ClassNotFoundException org.jdatepicker.UtilDateModel.as  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> (import '(org.jdatepicker.JDatePicker UtilDateModel as um))

ClassNotFoundException org.jdatepicker.JDatePicker.UtilDateModel  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> (import '(org.jdatepicker.JDatePicker UtilDateModel))

ClassNotFoundException org.jdatepicker.JDatePicker.UtilDateModel  java.net.URLClassLoader$1.run (URLClassLoader.java:366)
user=> 

======================= At least I am able to do this but I am not able to instantiate a JDatePicker yet.

user=> (import '(org.jdatepicker.JDatePicker))
nil
user=> (JDatePicker.)
CompilerException java.lang.IllegalArgumentException: No matching ctor found for interface org.jdatepicker.JDatePicker, compiling:(/tmp/form-init7437510410318747099.clj:1:1) 
user=> (doc JDatePicker)

CompilerException java.lang.RuntimeException: Expecting var, but JDatePicker is mapped to interface org.jdatepicker.JDatePicker, compiling:(/tmp/form-init7437510410318747099.clj:1:1) 

========================= Here, I see that JDatePicker wants to be instantiated using DefaultComponentFactory

public class TestJDatePicker {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) { }
JFrame testFrame = new JFrame();
testFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
testFrame.setSize(500, 500);
JPanel jPanel = new JPanel();
JDatePicker picker = new DefaultComponentFactory().createJDatePicker();
....

Getting closer

user=> (import '(javax.swing JComponent JFrame JPanel UIManager))
javax.swing.UIManager
user=> (UIManager/setLookAndFeel "com.sun.java.swing.plaf.windows.WindowsLookAndFeel")
UnsupportedLookAndFeelException [The Microsoft Windows Look and Feel - com.sun.java.swing.plaf.windows.WindowsLookAndFeel] not supported on this platform  javax.swing.UIManager.setLookAndFeel (UIManager.java:523)

This appears the preferred way to import things:

(import '(org.jdatepicker JDatePicker JDatePanel))
org.jdatepicker.JDatePanel
user=>
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Ivan
  • 7,448
  • 14
  • 69
  • 134
  • there is nothing called UtilDateModel anywhere in [jdatepicker](https://github.com/JDatePicker/JDatePicker) – noisesmith Dec 04 '14 at 22:20
  • how are you able to tell that? I tried (doc JDatePicker) but nothing comes back. In C/C++ I can look at a header file. – Ivan Dec 04 '14 at 22:53
  • That appears to be incorrect. Both are there user=> (import '(org.jdatepicker.impl UtilDateModel UtilCalendarModel)) – Ivan Dec 05 '14 at 00:06
  • It's not defined in any of the source files here https://github.com/JDatePicker/JDatePicker/tree/master/src/main/java/org/jdatepicker/impl – noisesmith Dec 05 '14 at 05:47
  • Drag the jdatepicker-1.3.4.jar file to the "Live Demo" section here http://jd.benow.ca/ and you can see it is there. The online source does not appear to be in sync with what is really in the jar file. – Ivan Dec 05 '14 at 16:45
  • No thank you I am able resolve all issues. See http://stackoverflow.com/questions/27323057/simple-clojure-java-interop-swing-program-cant-quite-get-it-to-work – Ivan Dec 06 '14 at 23:52
  • master branch online is the latest development branch, refer to the relevant tag in github if you want to see the source which is in sync with your jar, i.e. https://github.com/JDatePicker/JDatePicker/tree/jdatepicker-1.3.4 – juanheyns Jun 09 '15 at 21:54

0 Answers0