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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:45:30+00:00 2026-06-09T14:45:30+00:00

Still looking for a solution I have the following problem: I use SWT GC

  • 0

Still looking for a solution

I have the following problem: I use SWT GC to draw figures contained in GraphNodes to a Zest Graph.
As far as Linux and MacOS are concerned, everything works fine. But when I run my jar on Windows the nodes look very odd. The color is not painted correctly and there is no transparency (achieved via setAlpha() of GC).

Here are two screenshots to illustrate my problem:

Linux:

enter image description here

Windows:

enter image description here

EDIT:

I just created this working “mini” example to test out. If anybody has an idea, why the rectangle is black on windows, I would highly appreciate an answer. Here is the back.png image: This is the <code>back.png</code>

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.IContainer;

public class MiniExample
{
    public static void main(String[] args)
    {
        Display display = Display.getDefault();
        Shell shell = new Shell(display);

        Graph graph = new Graph(shell, SWT.NONE);
        graph.setSize(100, 100);

        CustomFigure fig = new CustomFigure(new Label());
        fig.setSize(-1, -1);
        CustomNode node = new CustomNode(graph, SWT.NONE, fig);
        node.setLocation(5, 5);

        shell.pack();
        shell.open();

        while(!shell.isDisposed())
        {
            if(!display.readAndDispatch())
                display.sleep();
        }
    }

    /* Minimal helper class for the figure */
    static class CustomFigure extends Figure
    {
        private Image background = new Image(Display.getDefault(), "back.png");
        private GC gcBack = new GC(background);
        private Label all = new Label(background);
        private Color blau =  new Color(Display.getDefault(), 19, 59, 94);

        public CustomFigure(Label label)
        {
            ToolbarLayout layout = new ToolbarLayout();
            setLayoutManager(layout);
            setMiddle(3);
            add(all);
        }

        /* The problem has to occur somewhere here... */
        public void setMiddle(int value)
        {
            gcBack.setBackground(blau);
            gcBack.setForeground(blau);
            gcBack.setAlpha(255);

            /* color background blue and draw the nr of connections */
            gcBack.drawRoundRectangle(6, 6, 15, 15, 3, 3);
            gcBack.fillRoundRectangle(6, 6, 15, 15, 3, 3);
            gcBack.setForeground(ColorConstants.white);
            gcBack.drawText(value+"", 9, 6, true);

            gcBack.setAlpha(255);

            all.repaint();
        }
    }

    /* Minimal helper class for the node */
    static class CustomNode extends GraphNode
    {
        public CustomNode(IContainer graphModel, int style, CustomFigure figure)
        {
            super(graphModel, style, figure);
        }
        @Override
        protected IFigure createFigureForModel()
        {
            return (IFigure) this.getData();
        }
    }
}
  • 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-09T14:45:31+00:00Added an answer on June 9, 2026 at 2:45 pm

    It is definitely your background image what causes the problem. I have run some tests with the following example. I used a pure white background image enter image description here and your background image enter image description here. All is fine with the white background image, but if I use your background image only black colors are painted. It is most likely a bug in SWT.

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.PaintEvent;
    import org.eclipse.swt.events.PaintListener;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.widgets.Canvas;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    
    public class MiniExample {
        public static void main( String[] args ) {
            Display display = Display.getDefault();
            Shell shell = new Shell( display );
    
            ACanvas canvas = new ACanvas( shell, SWT.None );
            canvas.setSize( 150, 150 );
    
            shell.pack();
            shell.open();
    
            while( !shell.isDisposed() ) {
                if( !display.readAndDispatch() )
                    display.sleep();
            }
        }
    
    static class ACanvas extends Canvas {
    
        public ACanvas( Composite parent, int style ) {
            super( parent, style );
    
            this.addPaintListener( new PaintListener() {
    
                @Override
                public void paintControl( PaintEvent arg0 ) {
                    int value = 5;
                    Image background = new Image( Display.getDefault(), "back2.png" );
                    GC gcBack = new GC( background );
                    //Color blue = Display.getDefault().getSystemColor( SWT.COLOR_BLUE );
                    Color blue = new Color( Display.getDefault(), 0, 0, 255 );
    
                    gcBack.setBackground( blue );
                    gcBack.setForeground( blue );
                    gcBack.setAlpha( 255 );
    
                    gcBack.drawRoundRectangle( 6, 6, 15, 15, 3, 3 );
                    gcBack.fillRoundRectangle( 6, 6, 15, 15, 3, 3 );
    
                    gcBack.setForeground( Display.getDefault().getSystemColor( SWT.COLOR_WHITE ) );
                    gcBack.drawText( value + "", 9, 6, true );
    
                    gcBack.setAlpha( 255 );
    
                    arg0.gc.drawImage( background, 0, 0 );
                }
    
            } );
        }
    
    }
    

    }

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

Sidebar

Related Questions

I'm looking for a solution to the following problem: I have an ActiveRecord entity
Hi I'm looking for a quick and easy solution to the following: I have
I still have issues reading UML diagrams. Just looking at the Builder pattern http://en.wikipedia.org/wiki/Builder_pattern
I have following problem. I want to create a file system based session storage
Help please, After numerous hours searching for the solution to my problem i have
Please if anyone knows the answer, I´m still looking for 3 days and nothing..
Been looking through other answers and I still don't understand the modulo for negative
I was looking at this code of a sieve of eratosthenes but i still
still a bit of a n00b on SharpSVN, I'm looking to get some simple
Looking at the docs of libavfilter it doesn't seem to be possible, but still,

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.