Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to select file with java.awt.FileDialog #105

Open
oeway opened this issue Sep 27, 2020 · 7 comments
Open

Unable to select file with java.awt.FileDialog #105

oeway opened this issue Sep 27, 2020 · 7 comments

Comments

@oeway
Copy link

oeway commented Sep 27, 2020

I am wondering how should we use java.awtFileDialog, considering the following example (copy and paste to https://javafiddle.leaningtech.com/ to test):

import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class JavaFiddle extends Frame {
     FileDialog fc;
     JavaFiddle() {
        super("MainClass");
        setSize(200, 100);
    
        fc = new FileDialog(this, "Choose a file", FileDialog.LOAD);

        Button b;
        add(b = new Button("Browse...")); // Create and add a Button
        b.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fc.setVisible(true);
            String fn = fc.getFile();
            if (fn == null)
              System.out.println("You cancelled the choice");
            else
              System.out.println("You chose " + fn);
          }
        });
      }
      
  public static void main(String[] args) {
      new JavaFiddle().setVisible(true);
  }
}

We can get the following interface:
Screenshot 2020-09-27 at 18 00 49

However, I am not sure how to proceed further since when I select a file, the only option I have is to close the file dialog. What's the correct way to use it?

Ideally, I would like be able to render a hidden dialog with an <input type="file"> element, when setVisible(true) is called, trigger the file dialog by fileInput.click() method. After selection, the file should mounted e.g. under /str (even better if this can be addressed with #98 ).

@rudosch
Copy link

rudosch commented Dec 10, 2021

I'm stuck with the same problem.
Are there any news on this issue ?

@alexp-sssup
Copy link
Member

Unfortunately no. AWT based application are currently not a priority for us, due to no commercial demand.

If you need support for this for an enterprise environment please get in touch: [email protected]

@rudosch
Copy link

rudosch commented Dec 10, 2021

So if I use JFileChooser all will work fine?

@alexp-sssup
Copy link
Member

With JFileChooser you will get a proper dialog, but remember that the filesystem is virtualized. You will not see the files on the disk as (of course) the browser does not allow arbitrary access to user's files.

We currently offer workarounds for this browser limitation to commercial users. We plan to eventually provide some form of integrated access to the disk, using modern HTML5 APIs.

@rudosch
Copy link

rudosch commented Dec 10, 2021

OK, I see. So I could provide some files on the virtual filesystem that could be chosen by JFileChooser?
Are there API methods to add files to the virtual file system without doing this in the Java classes?

@alexp-sssup
Copy link
Member

Please reads our docs here: https://docs.leaningtech.com/cheerpj/File-System-support

In particular the /str/ section.

@rudosch
Copy link

rudosch commented Dec 10, 2021

Thanks for you help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants