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

  • SEARCH
  • Home
  • 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 8452821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:36:06+00:00 2026-06-10T11:36:06+00:00

I have a method to create 2 buttons. These buttons are different than the

  • 0

I have a method to create 2 buttons. These buttons are different than the OK, Close buttons. They will perform different actions when clicked. I want the 2 buttons side by side and at the top of my base composite. Which is using GridLayout. I want to be able to place the buttons side by side.

Here is my createDialogArea that I am adding the method to.

  protected Control createDialogArea(Composite parent) {
  final Composite area = new Composite(parent, SWT.NONE);
  final GridLayout gridLayout = new GridLayout();
  gridLayout.marginWidth = 15;
  gridLayout.marginHeight = 10;
  area.setLayout(gridLayout);
  createTopButtons(area);
  createTableViewer(area);
  return area;
}

Here is the button method.

 protected void createTopButtons(Composite parent) {
   Button pdfButton = new Button(parent, SWT.PUSH);
   pdfButton.setText("Create PDF");
   pdfButton.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent e) {
        close();
     }
   }); 

   Button plotButton = new Button(parent, SWT.PUSH);
   plotButton.setText("Plot");
   plotButton.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent e) {
        close();
     }
   });  
 }

Would I need to add a Gridlayout to createTopButtons?
If so how would I get them side by side and not one on top of the other.

Also in the createDialogArea, can I arrange my components using the gridLayout?

Example – I want createTopButtons to be on the top left hand side, then I want createTableViewer centered

Do you arrange your items/buttons/labels using a layout inside the composite you are creating like createTopButtons. Then use a layout in the createDialogArea to arrange the composite created by the methods?

  • 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-10T11:36:08+00:00Added an answer on June 10, 2026 at 11:36 am

    Q & A

    Would I need to add a Gridlayout to createTopButtons?

    No you need to put your buttons in another composite and this child composite should have a gridlayout with two columns.

    Also in the createDialogArea, can I arrange my components using the
    gridLayout? Example – I want createTopButtons to be on the top left hand side, then I want createTableViewer centered

    Sure, why not. But you will also need something called GridData and set it like area.setLayoutData(gridData);. For centering something, your griddata may look like this gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false);

    Do you arrange your items/buttons/labels using a layout inside the
    composite you are creating like createTopButtons. Then use a layout in
    the createDialogArea to arrange the composite created by the methods?

    Yes. Though I dint get the second half composite created by the methods

    Code

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    
    public class SideBySide {
        public static void main(String[] args) {
            new SideBySide().start();
        }
    
        private Shell shell;
    
        public void start()
        {
            Display display = new Display();
            shell = new Shell(display);
            shell.setLayout(new GridLayout(1, true));
    
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            shell.setLayoutData(gridData);
    
            shell.setText("Side By Side");
    
            createDialogArea(shell);
    
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    
        protected Control createDialogArea(Composite parent) 
        {
            final Composite area = new Composite(parent, SWT.NONE);
            final GridLayout gridLayout = new GridLayout();
            gridLayout.marginWidth = 15;
            gridLayout.marginHeight = 10;
            area.setLayout(gridLayout);
    
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            shell.setLayoutData(gridData);
            area.setLayoutData(gridData);
    
            createTopButtons(area);
            createTableViewer(area);
            return area;
        }
    
        private void createTableViewer(Composite area)
        {
            Table table = new Table(area, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            table.setLayoutData(gridData);
    
            table.setLinesVisible(true);
            table.setHeaderVisible(true);
    
            TableColumn column = new TableColumn(table, SWT.LEFT);
            column.setWidth(320);
            column.setText("Column 1");
    
            column = new TableColumn(table, SWT.LEFT);
            column.setWidth(320);
            column.setText("Column 2");
        }
    
        protected void createTopButtons(Composite parent) 
        {
    
            Composite composite = new Composite(parent, SWT.NONE);
            GridLayout gridLayout = new GridLayout(2, false);
            gridLayout.marginWidth = 0;
            gridLayout.marginHeight = 0;
            gridLayout.verticalSpacing = 0;
            gridLayout.horizontalSpacing = 0;
            composite.setLayout(gridLayout);
    
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
            composite.setLayoutData(gridData);
    
            gridData = new GridData(SWT.DEFAULT, SWT.FILL, false, false);
    
            Button pdfButton = new Button(composite, SWT.PUSH);
            pdfButton.setText("Create PDF");
            pdfButton.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    shell.close();
                }
            }); 
    
            pdfButton.setLayoutData(gridData);
    
            Button plotButton = new Button(composite, SWT.PUSH);
            plotButton.setText("Plot");
            plotButton.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    shell.close();
                }
            });  
            plotButton.setLayoutData(gridData);
        }
    }
    

    Code Output

    enter image description here

    Further Reading

    This is a great article to understand layouts in SWT.

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

Sidebar

Related Questions

Hi I want to create a WCF service that have login method, which is
I want to create a Javascript class/object that allow me to have various method:
I have a create method in one controller and at the end of this
I create small application which is media player. I have method where I have
I have this method call: public DataTemplate Create(Type type, string propertyName) { string str
I have following spec to test controller method: context #create do it should redirect
I have a winforms, and it connecting wit webservice. Webservice has method which create
I have a winforms application and I am trying to create a method that
I have a web service method in which I create a particular type of
i want to create an application in one row of tableView there will be

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.