Black Magic
Black Magic

Reputation: 2766

SWT Text fields and buttons too small

This is the first time for me using SWT, and I am making a login shell like this:

loginshell = new Shell(swtFrameDisp,SWT.ON_TOP);
        loginshell.setLayout(new GridLayout(1, false));
        loginshell
                .setSize(textBoxHeight + 100, textBoxHeight + 100);

        GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true,
                false);

        // Center loginscreen!
        Monitor primary = swtFrameDisp.getPrimaryMonitor();
        Rectangle bounds = primary.getBounds();
        Rectangle rect = loginshell.getBounds();
        int x = bounds.x + (bounds.width - rect.width) / 2;
        int y = bounds.y + (bounds.height - rect.height) / 2;
        loginshell.setLocation(x, y);

        Label label = new Label(loginshell, SWT.NONE);
        label.setLayoutData(data);
        label.setText("Login to Messupport.com");

        // text field settings
        userNameField = new Text(loginshell, SWT.BORDER);
        userNameField.setLayoutData(data);
        userNameField.setTextLimit(100);
        userNameField.setText("username");

        passwordField = new Text(loginshell, SWT.PASSWORD
                | SWT.BORDER);
        passwordField.setLayoutData(data);
        passwordField.setBounds(100, 50, 100, 20);
        passwordField.setTextLimit(100);
        Button bn = new Button(loginshell, SWT.FLAT);
        bn.setLayoutData(data);
        bn.setText("Login");
        loginshell.setDefaultButton(bn);

However, the Text fields and my button are too small, I don't know why. But can anyone enlighten me? enter image description here

I already tried to use setBounds, but without results. So it's propably something with the layout. I would like to know how to solve this, thanks.

Upvotes: 0

Views: 581

Answers (1)

greg-449
greg-449

Reputation: 111217

You are using the same GridData object for all the controls. You must create a new GridData for each object as it is used to store layout information for the control.

From the GridData JavaDoc:

NOTE: Do not reuse GridData objects. Every control in a Composite that is managed by a GridLayout must have a unique GridData object.

Upvotes: 1

Related Questions