Skip to content

Commit

Permalink
支持pdf文件拖拽
Browse files Browse the repository at this point in the history
  • Loading branch information
ifnoelse committed Jun 22, 2017
1 parent 0050459 commit 7bba967
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/java/com/ifnoelse/pdf/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import com.ifnoelse.pdf.PDFUtil;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import javax.activation.MimetypesFileTypeMap;
import java.io.File;

/**
Expand All @@ -37,6 +42,7 @@ public void start(Stage primaryStage) throws Exception {
TextField filePath = new TextField();

filePath.setEditable(false);

BorderPane topPane = new BorderPane();
topPane.setCenter(filePath);

Expand All @@ -49,15 +55,32 @@ public void start(Stage primaryStage) throws Exception {
pageIndexOffset.setPrefWidth(100);




TextArea textArea = new TextArea();


textArea.setPromptText("请在此填入目录内容");

textArea.setOnDragEntered(e->{
Dragboard dragboard = e.getDragboard();
File file = dragboard.getFiles().get(0); //获取拖入的文件
String fileName = file.getName();
if(fileName.matches("[\\s\\S]+.[pP][dD][fF]$")){
filePath.setText(file.getPath());
}
});


vBox.setCenter(textArea);




vBox.setBottom(bottomPane);
Scene scene = new Scene(vBox, 600, 400);
primaryStage.setScene(scene);


fileSelectorBtn.setOnAction(event -> {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("pdf", "*.pdf"));
Expand Down

0 comments on commit 7bba967

Please sign in to comment.