Do I need a java program that can open the Open With dialog box on Windows, Mac and Linux?

How did I get a java program to open Open with a dialog box for windows as follows: -

File file = new file ("D: /new.txt");

ProcessBuilder builder = new ProcessBuilder ("RUNDLL32.EXE", "SHELL32.DLL, OpenAs_RunDLL", file.getAbsolutePath ());

    builder.redirectErrorStream();
    builder.redirectOutput();
    Process process = builder.start();
    process.waitFor();

But I want my code to work on Mac as well as Linux ??? Please give the right answer and link?

+4
source share
2 answers

You can choose JFileChooser, a java class that internally calls this on the entire platform. Example

JFileChooser (JavaDoc)

JFileChooser jfc= new JFileChooser() //You can choose the current directory or filesystemview
jfc.showOpenDialog() //or showSaveDialog(), it chooses the title of dialog and the viewform
jfc.getSelectedFile() //or Files[], get the value put on saving or file select in opening

( , ..). !

0

Popup JavaFX, Linux, Mac

   public void popup() {
            final Stage dialog = new Stage();
            dialog.setTitle("Confirmation");
            Button yes = new Button("Yes");
            Button no = new Button("No");

            Label displayLabel = new Label("What do you want to do ?");
            displayLabel.setFont(Font.font(null, FontWeight.BOLD, 14));

            dialog.initModality(Modality.NONE);
            dialog.initOwner((Stage) tableview.getScene().getWindow());

            HBox dialogHbox = new HBox(20);
            dialogHbox.setAlignment(Pos.CENTER);

            VBox dialogVbox1 = new VBox(20);
            dialogVbox1.setAlignment(Pos.CENTER_LEFT);

            VBox dialogVbox2 = new VBox(20);
            dialogVbox2.setAlignment(Pos.CENTER_RIGHT);

            dialogHbox.getChildren().add(displayLabel);
            dialogVbox1.getChildren().add(yes);
            dialogVbox2.getChildren().add(no);

            yes.addEventHandler(MouseEvent.MOUSE_CLICKED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {
                            // inside here you can use the minimize or close the previous stage//
                            dialog.close();
                        }
                    });
            no.addEventHandler(MouseEvent.MOUSE_CLICKED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {
                            dialog.close();
                        }
                    });

            dialogHbox.getChildren().addAll(dialogVbox1, dialogVbox2);
            Scene dialogScene = new Scene(dialogHbox, 500, 40);
            dialogScene.getStylesheets().add("//style sheet of your choice");
            dialog.setScene(dialogScene);
            dialog.show();
        }
0

Source: https://habr.com/ru/post/1523775/


All Articles