SWT DateTime Widget Schließen

Madlip

Bekanntes Mitglied
Hallo Community,

ich hab da so ein Problem.

Ich hab ein DateTime Widget und das in ein eigenes shell gepackt.

Nun will ich wenn der Benutzer außerhalb des shells klickt dass das Widget geschlossen wird, nur hab ich keine Ahnung wie ich das machen soll.

Hat einer von euch Tipps?

gruß
Mad
 
Hallo,

ne soweit bin ich da auch gekommen, ABER ich hab was ganz wichtiges vergeßen. Dieses DateTimeWidget ist ein ModalDialog, diese haben die Eigenschaft das sie den Focus "auf sich" setzten und andere Fenster "sperren" dadurch bringt mir der FocusListener nicht, dadurch bringt es mir auch nichts einen Listener auf die übergeordnete Group oder Shell zu setzten.

Lösung für das Problem ist, dass ich nun doch ein "Cancel" Button oder halt das "Exit" einblenden muss.

Trotzdem danke für deine Bemühung.
 
Wieso muss es denn ein Dialog sein?
Java:
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * [url=http://www.eclipse.org/legal/epl-v10.html]Eclipse Public License - Version 1.0[/url]
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/


/*
 * DateTime example snippet: create a DateTime calendar and a DateTime time.
 *
 * For a list of all SWT example snippets see
 * [url=http://www.eclipse.org/swt/snippets/]SWT Snippets[/url]
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet250 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout (new RowLayout ());

	final DateTime calendar = new DateTime (shell, SWT.CALENDAR);
	calendar.addSelectionListener (new SelectionAdapter () {
		public void widgetSelected (SelectionEvent e) {
			System.out.println ("calendar date changed");
		}
	});

	DateTime time = new DateTime (shell, SWT.TIME);
	time.addSelectionListener (new SelectionAdapter () {
		public void widgetSelected (SelectionEvent e) {
			System.out.println ("time changed");
		}
	});
	
	calendar.addFocusListener(new FocusAdapter()
	{
		public void focusLost(FocusEvent e)
		{
			((DateTime)e.getSource()).setVisible(false);
		}
	});
	
	Button b=new Button(shell, SWT.PUSH);
	b.setText("Show Calendar");
	b.addSelectionListener(new SelectionAdapter()
	{
		public void widgetSelected(SelectionEvent e)
		{
			calendar.setVisible(true);
		}
	});

	shell.pack ();
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
 

Zurück
Oben