我的SWT類中有一個方法從我的表中獲取選定的值。該值實際上是對象的文件名。SWT方法 - 從表格查看器獲取值/ Swing方法 - 使用值
public String getPDFFileName() {
int row = viewer.getTable().getSelectionIndex();
if (row != -1) {
return pdfFileName = AplotSaveDataModel.getInstance().getSelectedPDFFileName(row);
}
else {
MessageDialog.openError(null, "PDF Selection Error Message", "You need to select a PDF to view.");
}
return null;
}
我有一個橋接SWT和Swing的組合。此方法採用字符串文件名並創建一個顯示文件的Swing查看器。
protected Control createPDFButtons(Composite parent) {
final Composite swtAwtComponent = new Composite(parent, SWT.EMBEDDED);
GridData mainLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
mainLayoutData.horizontalSpan = 1;
swtAwtComponent.setLayoutData(mainLayoutData);
GridLayout mainLayout = new GridLayout(1, false);
mainLayout.marginWidth = 0;
mainLayout.marginHeight = 0;
swtAwtComponent.setLayout(mainLayout);
final Frame frame = SWT_AWT.new_Frame(swtAwtComponent);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
JButton viewerButton = new JButton("View Selected PDF");
viewerButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent actionevent) {
final File viewerFile = new File(getPDFFileName());
final AplotPdfViewer pdfv = new AplotPdfViewer(true);
try {
pdfv.openFile(viewerFile);
}
catch (IOException e) {
e.printStackTrace();
}
}
});
panel.add(viewerButton);
frame.add(panel);
return swtAwtComponent;
}
如果我嘗試運行在複合材料中的getPDFFileName(),我得到一個SWT線程錯誤。我明白這是從哪裏來的。
我不知道如何從getPDFFileName()獲取值並在最終文件中使用它viewerFile = new File(「NEED FILENAME OF SELECTION」);