SWT Window passt Größe nicht an

DavidRei

Mitglied
Hallo,
hab da ein kleines Problem.

Hab mit dem WindowBuilder eine Oberfläche erstellt auf der sich 3 Grp Elemente befinden. Bild:

Clipboard02.jpg - directupload.net

Nun zu dem Problem:
Die linke und rechte Group sollen ihre Breite beibehalten, zudem jeweils auf ihrer Seite bleiben. Lediglich die Mittlere Grp soll ihre Breite anpassen wenn man das Fenster vergrößert.

Habe es bisher leider nur geschafft alle Groups mit FillLayout anzupassen. Nur dann werden eben alle verändert.

Code der Implementierung der Groups:

Java:
protected void createContents() {
		shell = new Shell();
		shell.setText(PROGRAM_NAME);
		
		Group grpBauwerk = new Group(shell, SWT.NONE);
		grpBauwerk.setText(BAUWERK);
		grpBauwerk.setBounds(10, 10, 131, 494);
		
		Group grpLeistungsverzeichnis = new Group(shell, SWT.NONE);
		grpLeistungsverzeichnis.setText(LV);
		grpLeistungsverzeichnis.setBounds(147, 10, 411, 504);
		
		Group grpAuswahl = new Group(shell, SWT.NONE);
		grpAuswahl.setText(AUSWAHL);
		grpAuswahl.setBounds(564, 10, 186, 494);
		
		
		

	}
 
Verwende ein GridLayout oder ein FormLayout. Beim Ersten die erste und letzte Spalte mit fixer Grösse versehen, beim Zweiten die äusseren Groups an ihre jeweilige Position (mit fester Breite) setzen und die innere immer relativ zu den anderen Sätzen.
Die Layouts sollten sich ohne weiteres auch über den Builder setzen lassen...

Bsp: SWT - Tutorial

Achtung: Formlayout ist super praktisch, aber auch das performancehungrigste von denen.


Ok......
Weils so schnell geht (1 Minute - ernsthaft!)

Java:
import org.eclipse.swt.SWT;

public class Test2 extends Composite {
	
	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public Test2(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(3, false));
		
		Group grpLinks = new Group(this, SWT.NONE);
		GridData gd_grpLinks = new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1);
		gd_grpLinks.widthHint = 100;
		grpLinks.setLayoutData(gd_grpLinks);
		grpLinks.setText("links");
		
		Group grpMitte = new Group(this, SWT.NONE);
		grpMitte.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		grpMitte.setText("mitte");
		
		Group grpRechts = new Group(this, SWT.NONE);
		GridData gd_grpRechts = new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1);
		gd_grpRechts.widthHint = 100;
		grpRechts.setLayoutData(gd_grpRechts);
		grpRechts.setText("rechts");
		
	}
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
 
Ach so: Meine Main-Klasse...

Java:
import org.eclipse.swt.SWT;

public class Main {
	
	protected Shell shell;
	
	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Main window = new Main();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
	
	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		shell.setLayout(new GridLayout(1, false));
		Test2 test = new Test2(shell, SWT.NONE);
		test.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	}
}
 
Btw.: Nutze Resource-Bundles für Strings, dann hast du die Texte in Properties-Dateien und kannst auch noch schnell Übersetzung anbieten. darüber hinaus entwickle ich grundsätzlich ALLE Anwendungen in Englisch... Kann dieses verwurschtelte Denglisch nicht leiden!
 

Zurück
Oben