Duvida com swt abrir outra janela[Resolvido]

6 respostas
G

Bom dia, Estou com uma duvida assim super idiota mas eh que esta meio que fugindo de como eu eu programo portanto nao estou conseguindo fazer o mesmo, tenho uma pequena janela em que ela é chamada por um evento de um botao, porem nao estou conseguindo fazer isso.

tentei extender de DIalog so que nao deu mto certo, se alguem puder me ajudar com essa duvida agradeço

public class ValuesApplicationDialog {

	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display,SWT.SHELL_TRIM | SWT.TOOL);
		
		Button addButton;
		Button cancelButton;
		Text loginText;
		Text valueText;
		Label loginLabel;
		Label valueLabel;
		GridLayout layout = new GridLayout(2, false);
		shell.setLayout(layout);
				
		GridData d = new GridData();
		d.widthHint = 120;

		loginLabel = new Label(shell, SWT.NONE);
		loginLabel.setText("Parametro");

		loginText = new Text(shell, SWT.BORDER);
		loginText.setLayoutData(d);

		valueLabel = new Label(shell, SWT.NONE);
		valueLabel.setText("Valor");

		valueText = new Text(shell, SWT.BORDER);
		valueText.setLayoutData(d);
		
		addButton = new Button(shell,SWT.NONE);
		addButton.setText("Adicionar");
		
		cancelButton = new Button(shell,SWT.NONE);
		cancelButton.setText("Cancelar");
		cancelButton.addSelectionListener(new SelectionListener(){
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				
			}
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.close();
			}
		});
		
		shell.pack();
	    shell.open();
	    shell.setSize(220, 120);
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch()) {
	        display.sleep();
	      }
	    }
	    display.dispose();
	}
}

6 Respostas

thundercas

guialeixo,

Para mim não ficou clara a sua dúvida… Esse código que você postou é da tela que deve ser aberta quando o evento é acionado ou é a partir desta tela que o evento é acionado??

G

essa tela que deve abrir.
achei a soluçao
sei como funciona direito isso nao mas funciona auhauhaa

public class ValuesApplicationDialog extends Dialog{
	
	Object result;
	TableItem item;
	Text loginText;
	Text valueText;
	
	public ValuesApplicationDialog (Shell parent, int style) {
		super (parent, style);
	}
	public ValuesApplicationDialog (Shell parent) {
		this (parent, 0); 
	}
	public Object open () {
		Shell parent = getParent();
		final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setText(getText());
		
		Button addButton;
		Button cancelButton;
		Label loginLabel;
		Label valueLabel;
		GridLayout layout = new GridLayout(2, false);
		shell.setLayout(layout);
				
		GridData d = new GridData();
		d.widthHint = 120;

		loginLabel = new Label(shell, SWT.NONE);
		loginLabel.setText("Parametro");

		loginText = new Text(shell, SWT.BORDER);
		loginText.setLayoutData(d);

		valueLabel = new Label(shell, SWT.NONE);
		valueLabel.setText("Valor");

		valueText = new Text(shell, SWT.BORDER);
		valueText.setLayoutData(d);
		
		addButton = new Button(shell,SWT.NONE);
		addButton.setText("Adicionar");
		addButton.addSelectionListener(new SelectionListener(){

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
			@Override
			public void widgetSelected(SelectionEvent e) {
				item = new TableItem(ApplicationDialog.table,SWT.NONE);
				item.setText(new String[] { loginText.getText(),valueText.getText() });
			}
			
		});
		cancelButton = new Button(shell,SWT.NONE);
		cancelButton.setText("Cancelar");
		cancelButton.addSelectionListener(new SelectionListener(){
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				
			}
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.close();
			}
		});
		Display display = parent.getDisplay();
		shell.pack();
	    shell.open();
	    shell.setSize(220, 120);
	    
	    Monitor primary = display.getPrimaryMonitor();
	    Rectangle bounds = primary.getBounds();
	    Rectangle rect = shell.getBounds();
	    
	    int x = bounds.x + (bounds.width - rect.width) / 2;
	    int y = bounds.y + (bounds.height - rect.height) / 2;
	   
	    shell.setLocation(x, y);

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		return result;
	}
}
thundercas

hummmm… Mas cara, por que vc está usando SWT??? É trabalho acadêmico?? Do contrário, sugiro experimentar Swing.

abs

G

thundercas:
hummmm… Mas cara, por que vc está usando SWT??? É trabalho acadêmico?? Do contrário, sugiro experimentar Swing.

abs

cara swing eh mtoo complexo ahuahuahua… juro nao tenho a manha nenhuma em swing =) e estou desenvolvendo uma aplicação em RCP, eu tava com essa duvida pois sempre uso extends TitleAreaDialog dai eh bem mais simples, se voce tiver uma melhora nessa janela por favor me diga +)

thundercas

Então cara, nunca mexi com SWT não… Prefiro Swing… A interface é mais agradável e a performance melhorou muito de uns tempos pra cá… No começo é complicado mexer no Swing, mas depois que vc pega a manhã de trabalhar com os leiautes, você desenha qualquer tipo de tela.

G

mas acho q swt da pra fazer o tipo de tela que eu quiser tb =) eu trabalho so com layouts

mas de qualquer forma obrigado pela atençao

Criado 6 de novembro de 2009
Ultima resposta 6 de nov. de 2009
Respostas 6
Participantes 2