This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: problems with java.awt.FileDialog
- From: Per Bothner <per at bothner dot com>
- To: alex mitchell <lexaay at gmail dot com>
- Cc: "kawa at sources dot redhat dot com" <kawa at sources dot redhat dot com>
- Date: Fri, 11 Sep 2009 22:18:57 -0700
- Subject: Re: problems with java.awt.FileDialog
- References: <C6D09789.1E554%lexaay@gmail.com>
On 09/11/2009 09:10 AM, alex mitchell wrote:
I¹m resending this as my previous posts didn¹t seem to go through. Apologies
if this is a duplicate posting.
I had previously posted that I was having problems with
javax.swing.JFileChooser, specifically that it was hanging when invoking
'showOpenDialog. This seems to be a commonly reported bug, so I've switched
to java.awt.FileDialog. However, I'm still having problems. In the following
code, if I choose File->Open, the file dialog never appears. However, if I
call (test) directly, the file dialog appears immediately. Interestingly, if
I call (test) _after_ I've done File->Open, _both_ file dialog boxes appear.
Similarly, if I call (test) first, and then try to open a file from the
menu, the file dialog opens correctly. So it seems that calling (test) from
the actionListener causes it to hang trying to get the directory contents.
The equivalent code in Java doesn't have this problem, so I'm assuming this
is a Kawa issue. Anyone have any ideas?
Indeed, it seems to work on Fedora GNU/Linux.
How do you compile/run filetest.scm? Probably closest to the Java
version would be:
java kawa.repl --main -C filetest.scm
java filetest
Adding the following flags may also be a good idea:
--warn-undefined-variable --warn-inve-unknown-method --warn-as-error
I notice when I do that I get a lot of warnings, which means
you'll end up using reflection at run-time. I fixed those,
and got the attached program. You could try that.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
; test opening a file
(define-constant frame (javax.swing.JFrame "Test"))
(define-constant menu-bar (javax.swing.JMenuBar))
(define-constant m-menu (javax.swing.JMenu "Menu"))
(define-constant m-menu-item (javax.swing.JMenuItem "Open"))
(frame:setJMenuBar menu-bar)
(menu-bar:add m-menu)
(m-menu:add m-menu-item)
(m-menu-item:add-action-listener
(object (java.awt.event.ActionListener)
((action-performed e :: java.awt.event.ActionEvent) :: void
(test))))
(frame:pack)
(frame:setVisible #t)
(define (loadfile (f :: java.awt.Frame) title defDir fileType)
(let ((fd (java.awt.FileDialog f title (java.awt.FileDialog:LOAD))))
(fd:setFile fileType)
(fd:setDirectory defDir)
(fd:setLocation 50 50)
(fd:setVisible #t)
(fd:getFile)))
(define (test)
(format #t "Loading : ~a~%~!" (loadfile (java.awt.Frame) "Open..." ".\\"
"*.*")))