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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:21:29+00:00 2026-05-18T08:21:29+00:00

My window should allow two different kind of layouts (it’s a simple example to

  • 0

My window should allow two different kind of layouts (it’s a simple example to better illustrate it), e.g.

+-------------+-------------+-------------+
| Component 1 | Component 2 | Component 3 |
|             |             |             |
|             |             |             |
|             |             |             |
|             |             |             |
+-------------+-------------+-------------+

and

+-------------+---------------------------+
| Component 1 | Component 2               |
|             |                           |
|             +---------------------------+
|             | Component 3               |
|             |                           |
+-------------+---------------------------+

where the user can switch between both, e.g., using a menu item.

With SWT you need to provide the parent when creating a component. But we will need to (1) reuse the component and (2) place them in a different parent (similar to docking frameworks). How is this possible with SWT?

  • 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-05-18T08:21:29+00:00Added an answer on May 18, 2026 at 8:21 am

    You can simply do this by changing a component’s parent.

    setParent() changes the control’s parent, if the underlying operating system supports it. Then you can layout() the composite so the changes appear.

    Say you have three controls:

    • A composite c1 containing vertical controls
    • A composite c2 containing horizontal controls
    • A label lbl
    • A button btn

    Here’s the code:

    public class ControlSwitcher {
        public static void main(String[] args) {
            Display display = new Display();
            final Shell shell = new Shell(display);
            GridLayout gl = new GridLayout();
            gl.marginWidth = gl.marginHeight = 20;
            shell.setLayout(gl);
    
            final Composite c1 = new Composite(shell, SWT.NONE);
            c1.setBackground(new Color(display, 255, 160, 160));
            RowLayout layout = new RowLayout(SWT.VERTICAL);
            c1.setLayout(layout);
    
            final Composite c2 = new Composite(c1, SWT.NONE);
            c2.setBackground(new Color(display, 160, 255, 160));
            c2.setLayout(new RowLayout());
    
            final Label lbl = new Label(c2, SWT.NORMAL);
            lbl.setText("Hello world");
    
            final Button btn = new Button(c2, SWT.PUSH);
            btn.setText("Switch");
            btn.addSelectionListener(new SelectionListener() {
                @Override
                public void widgetSelected(SelectionEvent arg0) {
                    Composite target;
                    if (btn.getParent().equals(c2)) {
                        target = c1;
                    } else {
                        target = c2;
                    }
                    boolean success = btn.setParent(target);
                    if (success) {
                        target.pack();
                        shell.pack();
                    } else {
                        throw new RuntimeException("Not supported by this platform");
                    }
                }
    
                @Override
                public void widgetDefaultSelected(SelectionEvent arg0) {
                }
            });
    
            shell.pack();
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
            display.dispose();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user has entered a correct password, a login window should close and
Edit: Okay, this code still doesn't allow me to use two different textures in
I am trying to create a child window in WPF.this child window should open
I have a custom window (that should be on top of everything, including the
I am creating multiple video panels using vlcj. For each video window I should
This function works as it should, window.setInterval(function(){ var active = $('#frontpageControls a.active'); var next
I am trying to create a status window which content(textbox) should change in a
On Window 's load, every DD element inside Quote_App should have an onCLick event
I want to get a window like this How should i get this and
I want to develop a custom window system in c++ that should not depend

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.