Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT-从按钮打开对话框的最佳代码过程_Java_Swt - Fatal编程技术网

Java SWT-从按钮打开对话框的最佳代码过程

Java SWT-从按钮打开对话框的最佳代码过程,java,swt,Java,Swt,在我的主GUI应用程序上,有一个按钮可以打开单独的对话框。“新建”对话框有一个带有打印机列表的表。我不能让它工作。我敢肯定这对填充表是有好处的。下面是我正在使用的代码,以尝试使这项工作 Button plotButton = new Button(composite, SWT.PUSH); plotButton.setText("Select Plotter"); plotButton.addSelectionListener(new SelectionAdapter() {

在我的主GUI应用程序上,有一个按钮可以打开单独的对话框。“新建”对话框有一个带有打印机列表的表。我不能让它工作。我敢肯定这对填充表是有好处的。下面是我正在使用的代码,以尝试使这项工作

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中

  • 作为SWT程序员,您将如何解决这个问题

  • 编辑 添加表代码

    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;