This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

problems with java.awt.FileDialog


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?

thanks!
Alex

-- filetest.scm --

; test opening a file
(define frame (<javax.swing.JFrame> "Test"))
(define menu-bar (<javax.swing.JMenuBar>))
(define m-menu (<javax.swing.JMenu> "Menu"))
(define m-menu-item (<javax.swing.JMenuItem> "Open"))
(invoke (as <javax.swing.JFrame> frame) 'setJMenuBar menu-bar)
(invoke (as <java.awt.Container> menu-bar) 'add m-menu)
(invoke (as <java.awt.Container> m-menu) 'add m-menu-item)
(invoke m-menu-item 'add-action-listener
        (object (<java.awt.event.ActionListener>)
          ((action-performed e :: <java.awt.event.ActionEvent>) :: <void>
           (test))))
(invoke frame 'pack)
(invoke (as <java.awt.Component> frame) 'setVisible #t)

(define (loadfile f title defDir fileType)
                (let ((fd (<java.awt.FileDialog> f title
(<java.awt.FileDialog>:.LOAD))))
          (invoke fd 'setFile fileType)
          (invoke fd 'setDirectory defDir)
          (invoke fd 'setLocation 50 50)
          (invoke fd 'setVisible #t)
          (invoke fd 'getFile)))

(define (test)
  (format #t "Loading : ~a~%~!" (loadfile (<java.awt.Frame>) "Open..." ".\\"
"*.*")))

-- FileTest.java --

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class FileTest {
  public String loadFile(Frame f, String title, String defDir, String
fileType) {
    FileDialog fd = new FileDialog(f, title, FileDialog.LOAD);
    fd.setFile(fileType);
    fd.setDirectory(defDir);
    fd.setLocation(50, 50);
    fd.setVisible(Boolean.TRUE);
    return fd.getFile();
  }

  public static void main(String s[]) {
        final FileTest ft = new FileTest();
        final JFrame frame = new JFrame("test");
        JMenuBar menuBar = new JMenuBar();
        JMenu mMenu = new JMenu("Menu");
        JMenuItem mMenuItem = new JMenuItem("Open");
        frame.setJMenuBar(menuBar);
        menuBar.add(mMenu);
        mMenu.add(mMenuItem);
        mMenuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                System.out.println("Loading: " +ft.loadFile(frame,
"Open...", ".\\", "*.*"));
            }});
        frame.pack();
        frame.setVisible(Boolean.TRUE);
    }
}







Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]