Java SWT-从按钮打开对话框的最佳代码过程
在我的主GUI应用程序上,有一个按钮可以打开单独的对话框。“新建”对话框有一个带有打印机列表的表。我不能让它工作。我敢肯定这对填充表是有好处的。下面是我正在使用的代码,以尝试使这项工作Java SWT-从按钮打开对话框的最佳代码过程,java,swt,Java,Swt,在我的主GUI应用程序上,有一个按钮可以打开单独的对话框。“新建”对话框有一个带有打印机列表的表。我不能让它工作。我敢肯定这对填充表是有好处的。下面是我正在使用的代码,以尝试使这项工作 Button plotButton = new Button(composite, SWT.PUSH); plotButton.setText("Select Plotter"); plotButton.addSelectionListener(new SelectionAdapter() {
Button plotButton = new Button(composite, SWT.PUSH);
plotButton.setText("Select Plotter");
plotButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
startPrinterListOperation();
showFooBarDialog();
}
});
下面是showFooBarDialog()方法
在FooDialog中,我试图用服务器端调用累积的打印机填充一个表
private void startPrinterListOperation() {
listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session);
listOp.addOperationListener(new MyOperationListener(this) {
public void endOperationImpl() {
try {
printers = (ArrayList<PrinterProfile>) listOp.getPrinters();
}
finally {
listOp.removeOperationListener(this);
listOp = null;
}
}
});
session.queueOperation(listOp);
}
我认为这是ArrayList
尚未完成的地方,因此返回Null
startpinterlistooperation()
而不是单击按钮showFooBarDialog()代码>直到某个关于关闭的时间才执行
startInterlistOperation()
方法是否应该在FooDialog
中而不是在主Gui中private TableViewer createPlotterTable(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(parentDialog.getPrintersArray());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
return viewer;
}
编辑
表代码在单独的类中,而不是在主GUI类中
public class AplotPlotterDialog extends TitleAreaDialog {
private AplotBaseDialog parentDialog = null;
在代码片段中没有行
viewer.setInput(parentDialog.getPrinterArray())代码>。请提供包含此行的代码。好的,现在在上一个代码段中定义的parentDialog
在哪里?您是否尝试在新线程中调用打印机代码,并将结果分配给同步变量,以便变量释放后,该对话框将打开并显示数据。。只是个主意。是的,请看
private TableViewer createPlotterTable(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(parentDialog.getPrintersArray());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
return viewer;
}
public class AplotPlotterDialog extends TitleAreaDialog {
private AplotBaseDialog parentDialog = null;