Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [Minimize/Maximize and Restore the window] shows black ui for a moment.
[Minimize/Maximize and Restore the window] shows black ui for a moment. [message #1808389] Sun, 23 June 2019 13:36 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
Hello, I'm writing this message from Japan.
Sorry for my bad English.

[Minimize/Maximize and Restore the window] shows a black ui for a moment ( if the window contains a lot of Controls, Widgets). And it causes a little flicker (Even in a high performance PC).
This seems a bit ugly. So I'd like to prevent this behavior in my app.

This behavior also occurs in eclipse 4.9 which I'm currently using.
I think it is related with the SWT source code.

I'd like to show quickly loadable simple loading screen or simply use double buffer.
But I don't know where to tweak.

Is it possible by overriding some methods of Control or Composite?

I have tried SWT.DOUBLE_BUFFERED style in constructors but no luck.

Thank you very much in advance.
Best regards.

--My environments---
Windows 10
eclipse4.9 and using its SWT+JFace jar libraries.

[Updated on: Tue, 25 June 2019 19:37]

Report message to a moderator

Re: [Minimize and Restore the window] shows black ui for a moment. [message #1808464 is a reply to message #1808389] Tue, 25 June 2019 08:03 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
I wrote a small example (SSCCE).
https://i.imgur.com/PeNx78p.jpg

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;

public class BlackUI extends SWTApp {
	public static void main(String[] args) {
		var largeComposite  = launch(new FillLayout(), SWT.SHELL_TRIM);
		
		largeComposite.setLayout(new GridLayout());
		
		largeComposite.addPaintListener(e -> {
			//drawing its contents takes some time because it has many Controls.
			try {
				Thread.sleep(200);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		});
		
		var b = new Button(largeComposite, SWT.NONE);
		b.setText("BUTTON");
		
		loop(false);
	}
}


class SWTApp {
	private static Display display;
	private static Shell   shell;
	
	protected static Composite launch() {
		return launch(new FillLayout(), SWT.NONE);
	}
	
	protected static Composite launch( Layout layout , int shellStyle) {
		display = new Display();
		shell = new Shell(display, shellStyle);
		
		shell.setLayout(new FillLayout());
		Composite comp = new Composite(shell, SWT.None);
		comp.setLayout( layout );
		
		return comp;
	}
	
	protected static void loop() {
	    loop(true);
	}
	
	protected static void loop(boolean pack) {
		shell.open();
		if(pack) shell.pack();
		while( !shell.isDisposed() ) {
			if( !display.readAndDispatch() ) {
				display.sleep();
			}
		}
		display.dispose();
	}
}

[Updated on: Tue, 25 June 2019 19:24]

Report message to a moderator

Re: [Minimize and Restore the window] shows black ui for a moment. [message #1808719 is a reply to message #1808464] Sun, 30 June 2019 03:54 Go to previous messageGo to next message
Martin J is currently offline Martin JFriend
Messages: 50
Registered: August 2015
Member
Your "display.sleep()" will have InterruptedException. Use "try { ... } catch (Exception e)" block.
Re: [Minimize and Restore the window] shows black ui for a moment. [message #1808897 is a reply to message #1808719] Thu, 04 July 2019 08:02 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
Sorry I can't understand what you are trying to say.
display.sleep() never throws InterruptedException and my example can be executed without an error in my environment.

Display#sleep() only throws SWTException. You don't have to catch SWTException because it is a RuntimeException.
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FDisplay.html&anchor=sleep--

If you are talking about Thread.sleep() , my example already have a catch clause.

[Updated on: Thu, 04 July 2019 08:16]

Report message to a moderator

Re: [Minimize and Restore the window] shows black ui for a moment. [message #1822082 is a reply to message #1808897] Wed, 26 February 2020 23:37 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
I tried debugging the SWT code.

And I found that at the point of maximizing the window, button shows up normally.
But when Composite calls Control#fillBackground > OS.FillRect (which is native code), the black rectangle image appears.

The brush color was #F0F0F0 (COLOR_BTNFACE), so not black.
I don't know why FillRect leaves a weird black rectangle.

Other Windows Application does not show black rectangle like this, so this is the SWT's problem I think.

---org.eclipse.swt.widgets.Control.java
void fillBackground (long hDC, int pixel, RECT rect) {
	if (rect.left > rect.right || rect.top > rect.bottom) return;
	OS.FillRect (hDC, rect, findBrush (pixel, OS.BS_SOLID));
}

[Updated on: Wed, 26 February 2020 23:38]

Report message to a moderator

Re: [Minimize and Restore the window] shows black ui for a moment. [message #1822083 is a reply to message #1822082] Thu, 27 February 2020 00:14 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
I posted at bugzilla.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=560570
Re: [Minimize and Restore the window] shows black ui for a moment. [message #1834134 is a reply to message #1822083] Tue, 03 November 2020 14:58 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 43
Registered: July 2011
Member
I removed OS.WS_CLIPCHILDREN from Composite class.
It looks far better now.
Previous Topic:ImageData loader with 1bpp images
Next Topic:Crash when using recent versions of SWT on Linux
Goto Forum:
  


Current Time: Mon Dec 02 08:50:07 GMT 2024

Powered by FUDForum. Page generated in 0.03681 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top