2016-10-06 3 views
1

Arbeiten an einem SWT Jface Java Projekt bei Windowbuilder in Neon Eclipse. Haben 2 Composites in einer Shell, die für einen Event-Handler sichtbar gesetzt werden.SWT Composite nicht sichtbar im Fenster maximiert

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"); 

    } 
} 

Der Verbund wird durch den Event-Handler, sichtbar gemacht, aber während Fenster maximiert Verbund nicht mehr sichtbar, außer Ereignishandler wieder eingestellt wird.

Was ist zu tun, damit Composite sichtbar am Fenster maximiert wird?

+0

Sie müssen uns einen [mcve] –

+0

Posted Complete Code zeigen. Vielen Dank. – muhaass

Antwort

1

Sie haben StackLayout als Layout für die Shell angegeben. Es wird erwartet, dass jeweils genau ein untergeordnetes Steuerelement angezeigt wird, und Sie müssen das Feld topControl als Steuerelement festlegen, das angezeigt werden soll.

Sie müssen also etwas tun:

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

... 

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

nicht setVisible auf einem der Verbunde, da dies StackLayout zu verwirren rufen Sie.

+0

Gelöst mit layout.topControl. – muhaass

Verwandte Themen