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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:35:53+00:00 2026-06-01T06:35:53+00:00

I’m trying to display an SWT table inside a form section, but am having

  • 0

I’m trying to display an SWT table inside a form section, but am having problems with column resizing and scrolling.

I’ve attached some sample code that can be placed in a ViewPart of an Eclipse pluging (3.7 is the version I’m using). If you run the code, and resize the column to the right, the table gains a horizontal scrollbar (which is what I want).

Now if I collapse the section (click the arrow to the left of “Section Title”), the view gains a horizontal scrollbar (which i don’t want). Expanding the section again, the view scroll remains, and now the table no longer has one.

I’m looking for a way (probably some awful combination of nested composites) to stop the table being wider than the view, and would appreciate any suggestions.

public class ExampleView extends ViewPart {
  /** Note: other fields / methods removed to condense snippet */

  private FormToolkit toolkit;
  private ScrolledForm scrolledForm;

  public void createPartControl(Composite parent) {
            parent.setLayout(new FillLayout());

    toolkit = new FormToolkit(parent.getDisplay());
    scrolledForm = toolkit.createScrolledForm(parent);
    scrolledForm.setExpandHorizontal(true);
    scrolledForm.setText("Form Title");

    scrolledForm.getBody().setLayout(new FillLayout());
    // here's the modification for the solution
    scrolledForm.getBody().setLayout(
            new BoundedLayout(new FillLayout(), true));

    final Section section = toolkit.createSection(scrolledForm.getBody(),
            Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
                    | Section.EXPANDED);

    section.addExpansionListener(new ExpansionAdapter() {
        public void expansionStateChanged(ExpansionEvent e) {
            scrolledForm.reflow(true);
        }
    });
    section.setText("Section Title");

    final Table table = toolkit.createTable(section, SWT.FULL_SELECTION);
    TableViewer viewer = new TableViewer(table);

    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setItemCount(10);

    TableColumn col = new TableColumn(table, SWT.NONE);
    col.setText("Column A");
    col.setWidth(150);
    col.setResizable(true);
    col.setMoveable(true);

    TableColumn col2 = new TableColumn(table, SWT.NONE);
    col2.setText("Column B");
    col2.setWidth(150);
    col2.setResizable(true);
    col2.setMoveable(true);

    section.setClient(table);
  }
}
  • 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-01T06:35:55+00:00Added an answer on June 1, 2026 at 6:35 am

    So here’s a solution i’ve come up with using a custom Layout. It wraps another layout, but can bound the computeSize to either the width or height of the parent composite – basically only allowing scrolling in one direction (if there is an easier way to force the ScrolledForm to do this please let me know!).

    There are some nasty-ish reflection hacks that need to be applied as the computeSize and layout methods are protected

    import java.lang.reflect.Method;
    
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Layout;
    
    public class BoundedLayout extends Layout {
      protected Layout delegateLayout;
    
      protected Method computeSizeMethod;
      protected Method layoutMethod;
    
      protected boolean widthBound;
    
      public BoundedLayout(Layout delegateLayout, boolean widthBound) {
          setDelegateLayout(delegateLayout);
          this.widthBound = widthBound;
      }
    
      public Layout getDelegateLayout() {
          return delegateLayout;
      }
    
      public void setDelegateLayout(Layout delegateLayout) {
          this.delegateLayout = delegateLayout;
    
          try {
              computeSizeMethod = delegateLayout.getClass().getDeclaredMethod(
                    "computeSize", Composite.class, int.class, int.class,
                    boolean.class);
              computeSizeMethod.setAccessible(true);
    
              layoutMethod = delegateLayout.getClass().getDeclaredMethod(
                    "layout", Composite.class, boolean.class);
              layoutMethod.setAccessible(true);
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
      }
    
      @Override
      protected Point computeSize(Composite composite, int wHint, int hHint,
            boolean flushCache) {
        // get comp size to make sure we don't let any children exceed it
        Point compSize = composite.getSize();
    
        try {
            Point layoutComputedSize = (Point) computeSizeMethod.invoke(
                    delegateLayout, composite, wHint, hHint, flushCache);
    
            if (widthBound) {
                layoutComputedSize.x = Math.min(compSize.x,
                        layoutComputedSize.x);
            } else {
                layoutComputedSize.y = Math.min(compSize.y,
                        layoutComputedSize.y);
            }
    
            return layoutComputedSize;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
      }
    
      @Override
      protected void layout(Composite composite, boolean flushCache) {
        try {
            layoutMethod.invoke(delegateLayout, composite, flushCache);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.