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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:07:51+00:00 2026-06-10T08:07:51+00:00

I’ve just started working with swt’s canvas. I’m under the impression that draw commands

  • 0

I’ve just started working with swt’s canvas. I’m under the impression that draw commands from the graphics controller (gc) can be executed in any listener that is attached to the canvas. I guess though, my question is what triggers the paint listener method paintControl?

Does the canvas.redraw() cause this to run as well?

Thanks for anyone who can point me in the right direction. If there are tutorials or books I can read on the matter(2d drawing in swt in general as well), I would love to hear of them.

EDIT:
Here is the code, I’m running into an issue where the graphCanvas is not filling excess vertical space? It doesn’t work when I have it fill excessHorizontal space either. But it seems to work when I apply those properties to the composites. Any idea?

Color black = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
    chartComposite = new Composite(parent, SWT.NONE);
    GridLayout chartGridLayout = new GridLayout(1,false);
    GridData chartGridData = new GridData();
    chartGridData.grabExcessHorizontalSpace = true;
    chartGridData.grabExcessVerticalSpace = true;

    chartComposite.setLayout(chartGridLayout);
    chartComposite.setLayoutData(chartGridData);

    chartInnerComposite = new Composite(chartComposite, SWT.NONE);
    GridLayout chartInnerGridLayout = new GridLayout(2,false);
    GridData chartInnerGridData = new GridData();
    chartInnerGridData.grabExcessHorizontalSpace = true;
    chartInnerGridData.grabExcessVerticalSpace = true;
    chartInnerComposite.setLayout(chartInnerGridLayout);
    chartInnerComposite.setLayoutData(chartInnerGridData);
    /**
     * Create the four canvases
     */

    Canvas yCanvas = new Canvas(chartInnerComposite, SWT.None);
    graphCanvas = new Canvas(chartInnerComposite, SWT.None);
    GridLayout graphGridLayout = new GridLayout(1, false);
    graphGridLayout.makeColumnsEqualWidth = false;
    GridData graphGridData = new GridData(SWT.FILL);
    graphGridData.widthHint = 400;
    graphGridData.grabExcessVerticalSpace = true;
    graphCanvas.setLayout(graphGridLayout);
    graphCanvas.setLayoutData(graphGridData);
    graphCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.drawLine(20, 20, 500, 500);
            e.gc.drawRectangle(0, 0, graphCanvas.getSize().x -1, graphCanvas.getSize().y -1);

            e.gc.drawLine(0, 40, 500, 500);
            e.gc.drawLine(0, 0, 0, 1200);
            e.gc.drawLine(0, 0, 1200, 0);               
        }
    });
    /*graphCanvas.setSize(400, 400);
    graphCanvas.redraw();
    graphCanvas.update();*/


    Canvas filler = new Canvas(chartInnerComposite, SWT.NONE);
    Canvas xCanvas = new Canvas(chartInnerComposite, SWT.None);
  • 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-10T08:07:52+00:00Added an answer on June 10, 2026 at 8:07 am

    Your code can definitely call canvas.redraw() manually, which will then trigger a paintControl event. SWT itself will also cause repaints to be triggered as needed, for things like window resizing and when the canvas gets obscured/un-obscured by other windows.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.