我的 SWT 类中有一个方法可以从我的表中获取选定的值。该值实际上是对象的文件名。
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"); 中使用它