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 8452287
In Process

The Archive Base Latest Questions

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

I’ve been using SWT for a few years, but i can’t seem to figure

  • 0

I’ve been using SWT for a few years, but i can’t seem to figure this one out:

I need to SPLIT a VIEW into 2 “zones”: LEFT and RIGHT
So i use a Composite with GridLayout with 2 columns to do it.

Inside the RIGHT composite i have a FIXED number of columns (created inside another GridLayout composite) but inside the LEFT composite i need to create a DYNAMIC number of columns that spans on the composite limit…

Is there a way to achieve this?

I tried a RowLayout inside left composite, but these 2 don’t match :-\

Thanks

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

    As it is not clear what you mean by

    1. columns that spans on the composite limit
    2. I tried a RowLayout inside left composite, but these 2 don’t match

    Therefore I am assuming that you want a dynamically changing gridlayout for your left composite. See the code below, specially the button.addSelectionListener().

    import java.util.Random;
    
    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.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;
    
    public class DynamicComposite 
    {
        public static void main(String[] args) {
            new DynamicComposite().start();
        }
    
        private Composite compositeLeft;
        private Composite compositeRight;
        private Random rand;
    
        public void start()
        {
            rand = new Random(System.currentTimeMillis()); 
    
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new GridLayout(2, true));
            shell.setText("Dynamic Columns");
    
            createRightComposite(shell);
            createLeftComposite(shell);
            createButtonComposite(shell);
    
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    
        private void createButtonComposite(Shell shell) 
        {
            Label l = new Label(shell, SWT.SEPARATOR|SWT.HORIZONTAL);
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
            gridData.horizontalSpan = 2;
            l.setLayoutData(gridData);
    
            Button button = new Button(shell, SWT.PUSH);
            gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false);
            gridData.horizontalSpan = 2;
            button.setLayoutData(gridData);
            button.setText("Change Columns !!");
    
            button.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    if(compositeLeft == null || compositeLeft.isDisposed())
                        return;
    
                    GridLayout layout = (GridLayout)compositeLeft.getLayout();
                    int col = rand.nextInt(7);
                    if(col == 0)
                        col = 1;
                    layout.numColumns = col;
                    //compositeLeft.setLayout(layout);
                    compositeLeft.layout(); // You need to re-layout your composite
                }
            });
        }
    
        private void createRightComposite(Shell shell) 
        {
            compositeLeft = new Composite(shell, SWT.NONE);
            GridLayout gridLayout = new GridLayout(3, true);
            gridLayout.marginWidth = 0;
            gridLayout.marginHeight = 0;
            gridLayout.marginLeft = 0;
            gridLayout.marginRight= 0;
            gridLayout.marginTop = 0;
            gridLayout.marginBottom = 0;
            gridLayout.horizontalSpacing = 0;
    
            gridLayout.verticalSpacing = 0;
            gridLayout.horizontalSpacing = 0;
            compositeLeft.setLayout(gridLayout);
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            compositeLeft.setLayoutData(gridData);
    
            int counter = 17;
            for(int i=0; i<counter; i++)
            {
                Button button = new Button(compositeLeft, SWT.PUSH);
                button.setText("Button " + (i+1));
                GridData bData = new GridData(SWT.FILL, SWT.FILL, true, false);
                button.setLayoutData(bData);
            }
        }
    
        private void createLeftComposite(Shell shell) 
        {
            compositeRight = new Composite(shell, SWT.NONE);
            GridLayout gridLayout = new GridLayout(3, true);
            gridLayout.marginWidth = 0;
            gridLayout.marginHeight = 0;
            gridLayout.marginLeft = 0;
            gridLayout.marginRight= 0;
            gridLayout.marginTop = 0;
            gridLayout.marginBottom = 0;
            gridLayout.horizontalSpacing = 0;
            compositeRight.setLayout(gridLayout);
    
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            compositeRight.setLayoutData(gridData);
    
            int counter = 7;
            for(int i=0; i<counter; i++)
            {
                Button button = new Button(compositeRight, SWT.PUSH);
                button.setText("Button " + (i+1));
                GridData bData = new GridData(SWT.FILL, SWT.FILL, true, false);
                button.setLayoutData(bData);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I'm making a simple page using Google Maps API 3. My first. One marker

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.