How to make the 'open with' dialog box?

后端 未结 3 1507
南方客
南方客 2021-01-17 06:37

I made a program to search for .txt files.

If I click a file it means that the \"open with\" dialog box should appear, and that dialog box will contain a list of al

相关标签:
3条回答
  • 2021-01-17 06:43

    What Java code can I use to make the "open with" dialog box appear?

    To my knowledge, there is nothing in the J2SE like that. OTOH the Desktop API can open a File in whatever app. is the default consumer.

    0 讨论(0)
  • 2021-01-17 06:51

    You can make your own dialog for that purpose .And for coming how to get program list .on windows you can use registry . see this link Detecting installed programs via registry

    and also check how to acces registry via java read/write to Windows Registry using Java

    0 讨论(0)
  • 2021-01-17 06:59

    You should use FileChooser for this. Take a look here:

    //Create a file chooser
    final JFileChooser fc = new JFileChooser();
    ...
    //In response to a button click:
    int returnVal = fc.showOpenDialog(aComponent);
    
    
    public void actionPerformed(ActionEvent e) {
        //Handle open button action.
        if (e.getSource() == openButton) {
            int returnVal = fc.showOpenDialog(FileChooserDemo.this);
    
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                log.append("Opening: " + file.getName() + "." + newline);
            } else {
                log.append("Open command cancelled by user." + newline);
            }
       } ...
    }
    
    0 讨论(0)
提交回复
热议问题