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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:58:17+00:00 2026-05-24T00:58:17+00:00

I have a StyledText widget with embedded Table controls. However, once I add a

  • 0

I have a StyledText widget with embedded Table controls. However, once I add a MeasureItem listener to adjust the size of the table cells, the table appears at the top of the StyledText widget the first time I scroll, remaining there until I scroll all the way to the expected location.

Is this a known issue? Am I just doing something wrong?

Code snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.PaintObjectEvent;
import org.eclipse.swt.custom.PaintObjectListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.GlyphMetrics;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class JumpingTable {

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

        // Create editor
        StyledText styledText = new StyledText(shell, SWT.V_SCROLL);
        shell.setLayout(new FillLayout());

        // Insert lots of text
        for (int i=0; i<100; ++i) {
            styledText.append("Lorem ipsum\r\n");
        }

        // Create table
        Table table = new Table(styledText, SWT.NONE);
        table.setVisible(false); // *** prevents table from IMMEDIATELY jumping
        for (int i=0; i<3; ++i) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setWidth(100);
        }
        for (int i=0; i<3; ++i) {
            TableItem row = new TableItem(table, SWT.NONE);
            row.setText(new String[] {"a", "b", "c"});
        }

        // Place table
        int tableOffset = styledText.getCharCount();
        styledText.append("\uFFFC");  // Object Replacement Code
        StyleRange style = new StyleRange();
        style.start = tableOffset;
        style.length = 1;
        style.data = table;
        //table.pack();
        table.setSize(300, 150);  // accomodate MeasureItem's sizing
        Rectangle rect = table.getBounds();
        int ascent = 2*rect.height/3;
        int descent = rect.height - ascent;
        style.metrics = new GlyphMetrics(ascent, descent, rect.width);
        styledText.setStyleRange(style);

        // Draw table
        styledText.addPaintObjectListener(new PaintObjectListener() {

            @Override
            public void paintObject(PaintObjectEvent event) {
                Table table = (Table) event.style.data;
                table.setVisible(true);
                int y = event.y + event.ascent - event.style.metrics.ascent;
                table.setLocation(event.x, y);
            }   
        });

        // Adjust sizing
        table.addListener(SWT.MeasureItem, new Listener() {

            @Override
            public void handleEvent(Event event) {
                if (event.type == SWT.MeasureItem) {
                    event.width = 100;
                    event.height = 50;
                }
            }   
        });

        // Display GUI
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

        // Clean up
        display.dispose();
    }
}
  • 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-24T00:58:18+00:00Added an answer on May 24, 2026 at 12:58 am

    I have no idea, why are you doing this, but anyway..

    Your table isn’t located appropriately after creation, and it “sits” on base coordinates (0, 0). So you have to locate the table to right place.

    Add this line after styledText.setStyleRange(style); and it will work as you need.

    table.setLocation(styledText.getLocationAtOffset(styledText.getCharCount()));
    

    And then it’s not necessary, to have this line, you can delete it..

    table.setVisible(false); // *** prevents table from IMMEDIATELY jumping
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question really: SWT documentation says that if you're using styledText,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have some html documents like this: <HTML> <BODY> <p style=text-align:Left;font-size:20;font-family:Calibri;font-weight:normal;font-style:normal;color:#000000;> <span>asfsdf</span> </p> </BODY>
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How

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.