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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:21:52+00:00 2026-06-10T20:21:52+00:00

I’m trying to run a Java SWT GUI application in a headless environment and

  • 0

I’m trying to run a Java SWT GUI application in a headless environment and asked myself if there is an equivalent to the AWT option -Djava.awt.headless=true?

If not I will go for Xvfb or Xvnc, anyway I’m curious.

  • 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-10T20:21:54+00:00Added an answer on June 10, 2026 at 8:21 pm

    As per this very old bug report there is some problem with SWT headless mode. But again it is very old and was addressed for Mac OS.

    Q & A

    Asked myself if there is an equivalent to the AWT option
    “-Djava.awt.headless=true”?

    No there is no such property. Although on Win7 and with eclipse 4.2, you can operate in headless mode (just don’t do shell.open()).

    Code

    The code below opens a browser instance, waits for its load event and once the page is loaded then it dumps its page content and closes the shell. Also, it creates a color and an image in this headless mode.

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.browser.Browser;
    import org.eclipse.swt.browser.LocationEvent;
    import org.eclipse.swt.browser.LocationListener;
    import org.eclipse.swt.browser.ProgressEvent;
    import org.eclipse.swt.browser.ProgressListener;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.graphics.ImageData;
    import org.eclipse.swt.graphics.ImageLoader;
    import org.eclipse.swt.graphics.RGB;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    
    public class HeadLess 
    {
        public static void main(String[] args) {
            new HeadLess().start();
        }
    
        public void start()
        {
            Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setLayout(new GridLayout(1, true));
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            shell.setLayoutData(gridData);
    
            // Create browser and listen for events in headless mode
            final Browser browser = new Browser(shell, SWT.NONE);
            gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            browser.setLayoutData(gridData);
    
            browser.setUrl("https://stackoverflow.com/questions/12193231/is-there-an-equivalent-to-java-awt-headless-true-for-swt");
            browser.addProgressListener(new ProgressListener() {
                public void completed(ProgressEvent event) {
                    System.out.println(browser.getText());
                    shell.close();
                }
                public void changed(ProgressEvent event) {
                }
            });
    
            browser.addLocationListener(new LocationListener() {
                public void changing(LocationEvent event) {
                    System.out.println(event.location);
                }
                public void changed(LocationEvent event) {
                }
            });
    
            // Creating image in headless mode !!
            Color red = new Color(display, new RGB(255, 0, 0));
            Image image = new Image(display, 100, 100);
            GC gc = new GC(image);
            gc.setBackground(red);
            gc.fillRectangle(image.getBounds());
            gc.dispose();
    
            ImageLoader loader = new ImageLoader();
            loader.data = new ImageData[] {image.getImageData()};
            loader.save("swt.png", SWT.IMAGE_PNG);
    
            red.dispose();
            image.dispose();
    
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
    
            display.dispose();
        }
    }
    

    Additional

    1. swt browser in headless mode
    2. Easiest way to unit test SWT and Swing apps in a headless environment?
    • 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
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with 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.