0
我正在製作將打開pdf文件的JavaFX應用程序。我找到了PDF Viewer的免費庫,但它是在Swing中製作的。所以我需要將JPanel添加到ScrollPane(JavaFX)。我試過但沒有成功。將Swing組件添加到ScrollPane(JavaFX)
我得到這個錯誤:
2016年8月13日下午9時59分09秒org.icepdf.core.pobjects.Document 警告:PDF寫支持未在類路徑中找到。
我在這裏找到了stackoverflow如何將swing組件添加到javafx窗格,我這樣做,但我得到了這個錯誤。
任何建議是值得歡迎的。
package application;
import java.awt.Component;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import javafx.embed.swing.SwingNode;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
public class PDFView{
public JPanel viewerComponentPanel;
public static Node showPDF(File sFiles) throws MalformedURLException {
String filePath = sFiles.toURI().toURL().toString();
// build a controller
SwingController controller = new SwingController();
// Build a SwingViewFactory configured with the controller
SwingViewBuilder factory = new SwingViewBuilder(controller);
// Use the factory to build a JPanel that is pre-configured
//with a complete, active Viewer UI.
JPanel viewerComponentPanel = factory.buildViewerPanel();
// add copy keyboard command
ComponentKeyBinding.install(controller, viewerComponentPanel);
// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
controller.getDocumentViewController()));
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode, viewerComponentPanel);
// Open a PDF document to view
controller.openDocument(filePath);
return swingNode;
}
private static void createAndSetSwingContent(final SwingNode swingNode, JPanel viewerComponentPanel) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingNode.setContent(viewerComponentPanel);
}
});
}
}
這是主類,我稱之爲從PDFView類中的方法
for(int i=0;i<fileNumber;i++){
choosedName=sFiles[i].getName();
String ext=choosedName.substring(choosedName.lastIndexOf(".") + 1);
switch (ext) {
case "doc":
break;
case "docx":
break;
case "pdf":
tab = new Tab();
tab.setText(choosedName);
s1=new ScrollPane();
tab.setContent(s1);
s1.setContent(PDFView.showPDF(sFiles[i]));
tpane.getTabs().add(tab);
呀非常感謝你! – GlacialMan
是否可以更改我的應用程序內的框架大小。當我最大化我的應用程序時,PDF中的框架不會像我的應用程序的框架那樣做。 http://prntscr.com/c5mwnl – GlacialMan
與一些重量級的swing組件(與jpanel)使用swingnode有已知的問題。您可能更喜歡使用[基於javafx的pdf查看器](https://www.google.com.tr/?gfe_rd=cr&ei=eMCwV6-sF6zY8AfYroHwDw&gws_rd=ssl#safe=strict&q=javafx+pdf+viewer)。 – guleryuz