2016-10-06 4 views
1

Neon Eclipse의 windowbuilder에서 SWT Jface Java 프로젝트로 작업합니다. 이벤트 핸들러에 대해 표시되는 셸에 2 개의 Composite가 있습니다. SWT 컴포지트가 창에서 최대화되지 않음

package br.engenharia.investimentos; 

import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.custom.StackLayout; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.widgets.Menu; 
import org.eclipse.swt.widgets.MenuItem; 
import org.eclipse.swt.widgets.Group; 
import org.eclipse.wb.swt.SWTResourceManager; 
import org.eclipse.swt.layout.FormLayout; 
import org.eclipse.swt.widgets.Text; 
import org.eclipse.swt.layout.FormData; 
import org.eclipse.swt.layout.FormAttachment; 
import org.eclipse.swt.events.SelectionAdapter; 
import org.eclipse.swt.events.SelectionEvent; 
import org.eclipse.swt.layout.FillLayout; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.layout.RowLayout; 
import org.eclipse.swt.layout.RowData; 
import org.eclipse.swt.layout.GridData; 

public class Investimentos { 

    protected Shell shellSistemaInvestimentos; 
    private Text txtCompra; 

    /** 
    * Launch the application. 
    * @param args 
    */ 
    public static void main(String[] args) { 
     try { 
      Investimentos window = new Investimentos(); 
      window.open(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    /** 
    * Open the window. 
    */ 
    public void open() { 
     Display display = Display.getDefault(); 
     createContents(); 
     shellSistemaInvestimentos.open(); 
     shellSistemaInvestimentos.layout(); 
     while (!shellSistemaInvestimentos.isDisposed()) { 
      if (!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
    } 

    /** 
    * Create contents of the window. 
    */ 
    protected void createContents() { 
     shellSistemaInvestimentos = new Shell(); 
     shellSistemaInvestimentos.setSize(450, 300); 
     shellSistemaInvestimentos.setText("Sistema Investimentos"); 
     shellSistemaInvestimentos.setLayout(new StackLayout()); 

     Composite compositeAcoesCompra = new Composite(shellSistemaInvestimentos, SWT.NONE); 
     compositeAcoesCompra.setFont(SWTResourceManager.getFont("Segoe UI", 16, SWT.BOLD)); 
     compositeAcoesCompra.setLayout(new FormLayout()); 

     txtCompra = new Text(compositeAcoesCompra, SWT.BORDER | SWT.WRAP | SWT.CENTER); 
     FormData fd_txtCompra = new FormData(); 
     fd_txtCompra.top = new FormAttachment(0, 5); 
     fd_txtCompra.left = new FormAttachment(0); 
     fd_txtCompra.right = new FormAttachment(100); 
     txtCompra.setLayoutData(fd_txtCompra); 
     txtCompra.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND)); 
     txtCompra.setFont(SWTResourceManager.getFont("Segoe UI", 16, SWT.BOLD)); 
     txtCompra.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED)); 
     txtCompra.setText("A\u00E7\u00F5es - Compra"); 

     Composite compositeAcoesOperacao = new Composite(shellSistemaInvestimentos, SWT.NONE); 

     Composite compositeAcoesResultado = new Composite(shellSistemaInvestimentos, SWT.NONE); 

     Composite compositeAcoesEvento = new Composite(shellSistemaInvestimentos, SWT.NONE); 

     Menu menuPrincipalBar = new Menu(shellSistemaInvestimentos, SWT.BAR); 
     shellSistemaInvestimentos.setMenuBar(menuPrincipalBar); 

     MenuItem mntmAcoesSubmenu = new MenuItem(menuPrincipalBar, SWT.CASCADE); 
     mntmAcoesSubmenu.setText("A\u00E7\u00F5es"); 

     Menu menuAcoesCascade = new Menu(mntmAcoesSubmenu); 
     mntmAcoesSubmenu.setMenu(menuAcoesCascade); 

     //Set compositeAcoesCompra visible. After I'll make the same for others. 
     MenuItem mntmCompraItem = new MenuItem(menuAcoesCascade, SWT.NONE); 
     mntmCompraItem.addSelectionListener(new SelectionAdapter() { 
      @Override 
      public void widgetSelected(SelectionEvent e) { 
       compositeAcoesCompra.setVisible(true); 
       compositeAcoesOperacao.setVisible(false); 
       compositeAcoesResultado.setVisible(false); 
       compositeAcoesEvento.setVisible(false); 
      } 
     }); 
     mntmCompraItem.setText("Compra"); 

     MenuItem mntmOperacaoItem = new MenuItem(menuAcoesCascade, SWT.NONE); 
     mntmOperacaoItem.setText("Opera\u00E7\u00E3o"); 

     MenuItem mntmResultadoItem = new MenuItem(menuAcoesCascade, SWT.NONE); 
     mntmResultadoItem.setText("Resultado"); 

     MenuItem mntmEventoItem = new MenuItem(menuAcoesCascade, SWT.NONE); 
     mntmEventoItem.setText("Evento"); 

    } 
} 

컴포지트

이벤트 핸들러에 의해 표시되어 있지만, 이벤트 핸들러가 다시 설정되는 것을 제외하고 창을 최대화하면서 복합 더이상 보이지 않는다.

창가에서 합성물을 볼 수있게하려면 어떻게해야합니까?

+0

[mcve] –

+0

게시 된 전체 코드가 필요합니다. 감사. – muhaass

답변

1

StackLayout을 쉘의 레이아웃으로 지정했습니다. 이렇게하면 한 번에 하나의 하위 컨트롤 만 표시 될 것이므로 topControl 필드를 표시 할 컨트롤로 설정해야합니다. StackLayout을 혼동 할 것이다이 같은 복합의에 setVisible를 호출하지 마십시오

StackLayout layout = new StackLayout(); 
shellSistemaInvestimentos.setLayout(layout); 

... 

layout.topControl = compositeAcoesCompra; // whichever control you want to show 

:

그래서 당신이 뭔가를 할 필요가있다.

+0

layout.topControl을 사용하여 해결했습니다. – muhaass