Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Display not updating while application menu is open
Display not updating while application menu is open [message #749871] Tue, 25 October 2011 13:41 Go to next message
Sarah Missing name is currently offline Sarah Missing nameFriend
Messages: 4
Registered: July 2009
Junior Member
I'm running an application that uses a timer execution to update the display, creating a new composite and hiding the old one once the specified time has expired. In most cases this works fine, but if the application menu is open when the timer event fires then the new composite is not displayed. It appears that this is due to layout being called on the new composite with a flag of SWT.DEFER, meaning the layout will be deferred until display.readAndDispatch() is called. It appears that this call is not made while the menu is open. This leads me to two questions:

1.) Is it expected that display.readAndDispatch() will not be called while the application menu is open?
2.) Is there a way to programatically dismiss the open menu? I've found a couple very hacky ways to dismiss it, but don't really like them.


Here is a quick snippet that demonstrates the update behavior while the menu is open. There's a composite with a label added about every second. When the menu is not open, you'll see the labels added (up to 30). Once the menu is open, the application does not display the new labels until the menu is dismissed and then all labels added while the menu was open will be visible. If you uncomment the display.readAndDispatch() line, then the newly added labels will be visible in the display while the menu is open.


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class MenuTestApp {

private static int RUN_COUNT = 0;

/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
GridLayout gridLayout = new GridLayout(10, true);
gridLayout.marginTop = 20;
shell.setLayout(gridLayout);
shell.setSize(800, 200);

final Menu menu = new Menu(shell, SWT.BAR);
final MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
menuItem.setText("Open Menu");
final Menu menu2 = new Menu(menuItem);
menuItem.setMenu(menu2);
final MenuItem menuItem2 = new MenuItem(menu2, SWT.CASCADE);
menuItem2.setText("Display stops updating");

shell.setMenuBar(menu);

final Runnable timer = new Runnable() {
@Override
public void run() {
++RUN_COUNT;
final Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout());
final Label label = new Label(composite, SWT.NONE);
label.setText("Updated " + RUN_COUNT);
final Control[] controls = { label };
composite.layout(controls, SWT.DEFER);
shell.layout(true, true);
shell.update();
if (RUN_COUNT < 30) {
display.timerExec(1000, this);
}

// Uncomment this line and the display will update correctly
// display.readAndDispatch();
}
};
display.timerExec(500, timer);

shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Re: Display not updating while application menu is open [message #750010 is a reply to message #749871] Tue, 25 October 2011 15:22 Go to previous messageGo to next message
Thomas Singer is currently offline Thomas SingerFriend
Messages: 75
Registered: July 2009
Member
Are you talking about the OS X application menu?
Re: Display not updating while application menu is open [message #750170 is a reply to message #750010] Tue, 25 October 2011 17:07 Go to previous message
Sarah Missing name is currently offline Sarah Missing nameFriend
Messages: 4
Registered: July 2009
Junior Member
I can see the problem both in the OS X application menu as well as with the Windows application menu.
Previous Topic:Compatibility problem with Myspace and SWT Browser
Next Topic:Sample SWT Browser Plug-in Source attached
Goto Forum:
  


Current Time: Thu Apr 25 05:38:37 GMT 2024

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

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

Back to the top