Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:28:34+00:00 2026-06-12T09:28:34+00:00

I working with SWT and am having some issues laying things out the way

  • 0

I working with SWT and am having some issues laying things out the way I want. Essentially I have a Text object that I want to have its width be what ever the width of the component it is located in is. I could use FillLayout but then the button below it would also grow, which is not what I want.

Here is a screen shot to illustrate the problem:
enter image description here

Here is a the test code I am using to reproduce, and try to fix the problem:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;


public class Test {

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

        shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        //setup the layout manager      
        GridLayout layout = new GridLayout(1, false);
        layout.horizontalSpacing = 0;
        layout.marginHeight = 0;
        layout.verticalSpacing = 5;
        layout.marginWidth = 0;
        layout.marginBottom = 20;
        layout.marginTop = 5;       

        shell.setLayout(layout);

        //create the text field
        Text inputField = new Text(shell, SWT.BORDER);
        GridData data =  new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.grabExcessHorizontalSpace = true;
        inputField.setData(data);

        //create the button
        Button lookup = new Button(shell, SWT.PUSH);
        lookup.setText("Lookup");       


        shell.pack();
        shell.open();

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

I assume it is just I am not setting something correctly on the GridData object for the inputField, but whatever it is I am definitely not seeing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:28:35+00:00Added an answer on June 12, 2026 at 9:28 am

    You have to use setLayoutData() to set the GridData not setData():

    Text inputField = new Text(shell, SWT.BORDER);
    GridData data =  new GridData();
    data.horizontalAlignment = SWT.FILL;
    data.grabExcessHorizontalSpace = true;
    inputField.setLayoutData(data);
    

    BTW: the use of GridData.FILL is not recommended, use SWT.FILL instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on laying out a perspective in SWT. To make things simple, it
I am working on SWT based GUI application. I have one object variable which
I'm working on an application that uses the SWT Browser widget to display an
I've just started working with swt's canvas. I'm under the impression that draw commands
I working on an SWT Tree where each TreeItem needs to have multiple images
In a tool, I'm working on, I have a table, that I add like
In order to understand how JFace databindings is working, I have a model object
I am working on an Eclipse RCP-based application, and we have decided that we
I have been working on a SWT-based project which is intended to be deployed
I'm working on an SWT app, and although I greatly appreciate the way SWT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.