Problem mit GridLayout und pack()

stefangraf

Grünschnabel
Hallo zusammen
Ich habe ein etwas komisches Problem in der Darstellung meines GUI (SWT).
Nach dem Start des Programmes sieht das GUI gut aus. Wenn ich jedoch eine Windows shell eine Instanz eines Applikationsservers starte verändern gewisse Elemente meines GUI ihre Grösse. Das kann ich mir nicht wirklich erklähren, da das SWT-GUI rein garnichts mit dem dem Applikationsserver zu tun hat.

Konkret habe ich eine Group auf welcher verschidene GUI-Komponenten plaziert sind. Mittels widthHint habe ich den Komponenten eine bestimmte Breite zugewiesen. Als Layout verwende ich GridLayout.

Ich habe den Code so weit wie möglich ausgedünnt, das ich den Fehler noch reproduzieren konnte.

Hat jemand einen Tip an was es liegen könnte?
Unten sind noch zwei Bilder angehängt die das GUI zeigen bevor und nach der Veränderung.


Code:
package com.csg.bam.usermanagement;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * the class represents the GUI of the BAM UserManager
 */
public class GUI {
	// Constants 
	private static String APPLICATION_NAME 						= "BAM UserManager";	
	private static int 	  SHELL_WIDTH  							= 800; // with of the shell
	private static int 	  SHELL_HEIGHT 							= 700; // height of the shell
	private static int 	  TABLE_HEIGHT_DELTA 					= 293; // delta between the height of the shell and the height of the table
	private static int 	  TABLE_WIDTH_DELTA 					= 30;  // delta between the width of the shell and the width of the table
	private static int 	  COMPONENT_WIDTH 						= 118; // width if a componens (combo, label, text)
	private static int 	  DB_CONSTRAINT_STRING_LENGTH 			= 200; // maximum characters allowed to insert in a varchar (defined in the db)
	private static int 	  LOGICAL_CONSTRAINT_PID_STRING_LENGTH 	= 7;   // length of a PID
	
	// global variables
	private Display 	display				= null;
	private Shell 		shell				= null;
	private TabFolder 	tabfolder			= null;
	private Composite	composite_2_addrem	= null;
	
	// groups used to group the content of the different tabs
	// a "1" in the name indicates that the group is used in the
	// first tab, ...
	private Group 		group_2_add_user		= null;
	private Group 		group_2_add_application	= null;

	// text fields used for the text imput
	private Text text_2_userName		= null;
	private Text text_2_userSurname		= null;
	private Text text_2_applicationDesc	= null;
	
	// combos to dispay the entries in the database
	private Combo combo_2_user_pid					= null;
	private Combo combo_2_application_name			= null;

	//Griddata 
	private GridData gdFill = new GridData ();
	private GridData gdFIll_twoColumns = new GridData ();		
	GridData gdTable = new GridData ();
	

	/**
	 * constructor initializing the GUI
	 * @param vec 
	 * @param _dbwriter
	 */
	public GUI(Databasewriter _dbwriter, Databasereader _dbreader, LDAPreader _ldap){

		// create shell content
		initialize();

		// swt standard code
		shell.open();
		while (!shell.isDisposed()){
			if (!display.readAndDispatch()){
				display.sleep();
			}
		}
		display.dispose();
	}
	
	/**
	 * create the the different tabs of the GUI
	 * @param resultVec
	 */
	private void initialize() {
		// create shell
		display = new Display();

		shell = new Shell(display, SWT.CLOSE | SWT.MIN);
		shell.setText(APPLICATION_NAME);
		shell.setLayout(new GridLayout(1, true));
		shell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
		shell.setMinimumSize(SHELL_WIDTH, SHELL_HEIGHT);
		shell.setImage(new Image(display, "images/icon.gif"));



		// create tabfolder
		tabfolder = new TabFolder(shell, SWT.CENTER);
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		tabfolder.setLayoutData(gd);
	
		
		// set the global griddata 
		gdFill.widthHint = COMPONENT_WIDTH;
		gdFill.horizontalAlignment = GridData.FILL;
		gdFill.verticalAlignment   = GridData.FILL;
		
		gdFIll_twoColumns.horizontalAlignment = GridData.FILL;
		gdFIll_twoColumns.verticalAlignment   = GridData.FILL;
		gdFIll_twoColumns.horizontalSpan = 2;
		
		gdTable.grabExcessHorizontalSpace = true;
		gdTable.grabExcessHorizontalSpace = true;
		gdTable.heightHint = SHELL_HEIGHT - TABLE_HEIGHT_DELTA;
		gdTable.minimumWidth  = SHELL_WIDTH - TABLE_WIDTH_DELTA;
		
		
		initialize_2_tab_objects();
		
		group_2_add_user.pack();
		group_2_add_application.pack();
	}

	/**
	 * the method initialaizes the GUI-tab "add/remove objects"
	 */
	private void initialize_2_tab_objects() {
		// tabitem / composite
		TabItem ti_addrem = new TabItem(tabfolder, SWT.NONE);
		ti_addrem.setText("add/remove objects");
		composite_2_addrem = new Composite(tabfolder, SWT.NONE);
		composite_2_addrem.setLayout(new GridLayout(1, true));
		ti_addrem.setControl(composite_2_addrem);		
		
		// layout
		GridLayout gridLayout = new GridLayout ();
		gridLayout.numColumns = 5;
		gridLayout.makeColumnsEqualWidth = false;
		
		// group user
		group_2_add_user = new Group(composite_2_addrem, SWT.NONE);
		group_2_add_user.setText("user");
		group_2_add_user.setLayout(gridLayout);
	
		// group application
		group_2_add_application = new Group(composite_2_addrem, SWT.NONE);
		group_2_add_application.setText("application");
		group_2_add_application.setLayout(gridLayout);
	
		
		// USER
		//******************
		addLabel(group_2_add_user, "", gdFill);
		addLabel(group_2_add_user, "", gdFill);
		addLabel(group_2_add_user, "PID", gdFill);
		addLabel(group_2_add_user, "name", gdFill);
		addLabel(group_2_add_user, "surname", gdFill);
		Button button_userAdd	= new Button(group_2_add_user, SWT.NONE);
		Button button_userRem	= new Button(group_2_add_user, SWT.NONE);
		combo_2_user_pid		= new Combo(group_2_add_user, SWT.DROP_DOWN);
		text_2_userName			= new Text(group_2_add_user, SWT.BORDER);
		text_2_userSurname		= new Text(group_2_add_user, SWT.BORDER);
		addLabel(group_2_add_user, "", gdFill);
		addLabel(group_2_add_user, "", gdFill);
		Button button_user_LDAP_pid	 = new Button(group_2_add_user, SWT.NONE);
		addLabel(group_2_add_user, "", gdFill);
		Button button_user_LDAP_name = new Button(group_2_add_user, SWT.NONE);
		
		button_userAdd.setText("add");
		button_userRem.setText("remove");
		button_user_LDAP_pid.setText("LDAP lookup (PID)");
		button_user_LDAP_name.setText("LDAP lookup (surname)");
		combo_2_user_pid.setToolTipText("A PID must match the patten: 1 letter and 6 numbers (e.g. \"a123456\")");
		combo_2_user_pid.setTextLimit(LOGICAL_CONSTRAINT_PID_STRING_LENGTH);
		text_2_userName.setTextLimit(DB_CONSTRAINT_STRING_LENGTH);
		text_2_userSurname.setTextLimit(DB_CONSTRAINT_STRING_LENGTH);
		
		button_userAdd.setLayoutData(gdFill);
		button_userRem.setLayoutData(gdFill);
		button_user_LDAP_pid.setLayoutData(gdFill);
		button_user_LDAP_name.setLayoutData(gdFill);
		combo_2_user_pid.setLayoutData(gdFill);
		text_2_userName.setLayoutData(gdFill);
		text_2_userSurname.setLayoutData(gdFill);
		
		
		// APPLICATION
		//******************
		addLabel(group_2_add_application, "", gdFill);
		addLabel(group_2_add_application, "", gdFill);
		addLabel(group_2_add_application, "name", gdFill);
		addLabel(group_2_add_application, "description", gdFill);
		addLabel(group_2_add_application, "", gdFill);
		Button button_applicationAdd	= new Button(group_2_add_application, SWT.NONE);
		Button button_applicationRem	= new Button(group_2_add_application, SWT.NONE);
		combo_2_application_name		= new Combo(group_2_add_application, SWT.DROP_DOWN);
		text_2_applicationDesc			= new Text(group_2_add_application, SWT.BORDER);
		
		button_applicationAdd.setText("add");
		button_applicationRem.setText("remove");
		combo_2_application_name.setToolTipText("The applicationName must match the rootContext of the application");
		combo_2_application_name.setTextLimit(DB_CONSTRAINT_STRING_LENGTH);
		text_2_applicationDesc.setTextLimit(DB_CONSTRAINT_STRING_LENGTH);
		
		button_applicationAdd.setLayoutData(gdFill);	
		button_applicationRem.setLayoutData(gdFill);	
		combo_2_application_name.setLayoutData(gdFill);	
		text_2_applicationDesc.setLayoutData(gdFIll_twoColumns);
	}
	
	/**
	 * the metod adds a label to the composite and sets the text and the griddataS
	 * @param composite composite the label is displayed on
	 * @param text text show by the composite
	 * @param gd griddata of the label
	 */
	private void addLabel(Composite composite, String text, GridData gd){
		Label l = new Label(composite, SWT.None);
		l.setText(text);
		l.setLayoutData(gd);
	}
}
 

Anhänge

  • OK.jpg
    OK.jpg
    15,2 KB · Aufrufe: 98
  • bad.jpg
    bad.jpg
    13,3 KB · Aufrufe: 79
Zurück