-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWT org.eclipse.swt.widgets.Menu: a very tall menu exceeding the screen when scrolled has the effect to blank the neighboring menus #2349
Comments
Screenshot would help. I believe it's a known GTK issue we reported some years ago to GTK, @trancexpress ? |
I will rework my menu to fit the screen. |
We had/have: https://bugs.eclipse.org/bugs/show_bug.cgi?id=564910 Without a video its hard to tell if its the same issue. |
vokoscreenNG-2024-10-02_22-06-18.mp4The issue is shown twice in this recording. Best regards, |
We've not ran into this issue yet. If I find time I'll try to come up with a GTK3 repoducer. Maybe its again some weird combo behavior (menus share code with combo drop downs) that is supposed to make to make a combo entry easy to click (due to mouse pointer proximity)... |
I tried a few reproducers, I couldn't reproduce the problem with GTK3. Next step here should be an SWT snippet that reproduces the problem, maybe with that we can reduce to a GTK3 snippet. I doubt its an SWT bug, I assume its some GTK3 bug. |
Hello, I have verified that the issue was not due to X11 but the behaviour is exactly the same with Wayland. Best regards, |
Hello, Please find below a code snippet reproducing the issue. package org.eclipse.swt.snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class Snippet
{
public static void main (final String [] args)
{
final var display = new Display ();
final var shell = new Shell (display);
shell.setText ("Snippet");
shell.setLayout (new FillLayout ());
final var tree = new Tree (shell, SWT.FULL_SELECTION);
final var menu = new Menu (tree);
tree.setMenu (menu);
menu.addMenuListener (MenuListener.menuShownAdapter (e -> build_menu (tree, menu)));
final var nb_menu_entry = new int [] {4, 80, 8};
for (int i = 0; i < 2; i++)
{
final var item_I = new TreeItem (tree, SWT.NONE);
item_I.setText ("Level 1 - " + i);
for (int j = 0; j < nb_menu_entry.length; j++)
{
final var item_J = new TreeItem (item_I, SWT.NONE);
item_J.setText ("Level 2 - " + j);
item_J.setData (Integer.valueOf (nb_menu_entry [j]));
}
}
shell.setSize (800, 600);
shell.open ();
while (! shell.isDisposed ())
{
if (! display.readAndDispatch ())
{
display.sleep ();
}
}
display.dispose ();
}
static private void build_menu (final Tree tree, final Menu menu)
{
final TreeItem [] selection = tree.getSelection ();
if (selection.length != 0)
{
final TreeItem tree_item = selection [0];
final var nb_entry = (Integer) tree_item.getData ();
clear_menu (menu);
if (nb_entry != null)
{
for (int i = 0; i < nb_entry.intValue (); i++)
{
final var item = new MenuItem (menu, SWT.PUSH);
item.setText ("Menu entry " + i);
item.addSelectionListener (SelectionListener.widgetSelectedAdapter (e -> System.out.println ("Coucou")));
}
}
}
}
static private void clear_menu (final Menu menu)
{
for (final MenuItem menu_item : menu.getItems ())
{
final Menu child = menu_item.getMenu ();
if (child != null)
{
clear_menu (child);
}
menu_item.dispose ();
}
}
} Best regards, |
The behavior is reproducible with this GTK+ snippet:
I assume when reusing the same menu, the scroll state is preserved despite removing items. I don't find any option in SWT to scroll the menu programmatically. @backwindj are you able to use several SWT menu objects? Likely this will be the easiest option for a workaround. I assume the GTK3 behavior here is expected, to fix this behavior some sort of a workaround will be needed. |
Hello, I think I have found a general workaround with only one menu. The menu has to be disposed and recreated when closed: package org.eclipse.swt.snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class Snippet
{
public static void main (String [] args)
{
final var display = new Display ();
final var shell = new Shell (display);
shell.setText ("Snippet");
shell.setLayout (new FillLayout ());
final var tree = new Tree (shell, SWT.FULL_SELECTION);
final var menu = new Menu (tree);
menu.addMenuListener (MenuListener.menuShownAdapter (e -> build_menu (tree)));
tree.setMenu (menu);
final var nb_menu_entry = new int [] {4, 80, 8};
for (int i = 0; i < 2; i++)
{
final var item_I = new TreeItem (tree, SWT.NONE);
item_I.setText ("Level 1 - " + i);
for (int j = 0; j < nb_menu_entry.length; j++)
{
final var item_J = new TreeItem (item_I, SWT.NONE);
item_J.setText ("Level 2 - " + j);
item_J.setData (Integer.valueOf (nb_menu_entry [j]));
}
}
shell.setSize (800, 600);
shell.open ();
while (! shell.isDisposed ())
{
if (! display.readAndDispatch ())
{
display.sleep ();
}
}
display.dispose ();
}
static private void build_menu (final Tree tree)
{
final TreeItem [] selection = tree.getSelection ();
if (selection.length != 0)
{
final TreeItem tree_item = selection [0];
final var nb_entry = (Integer) tree_item.getData ();
if (nb_entry != null)
{
final Menu menu = tree.getMenu ();
clear_menu (menu);
menu.addMenuListener (MenuListener.menuHiddenAdapter (e -> dispose_menu (tree)));
for (int i = 0; i < nb_entry.intValue (); i++)
{
final var item = new MenuItem (menu, SWT.PUSH);
item.setText ("Menu entry " + i);
item.addSelectionListener (SelectionListener.widgetSelectedAdapter (e -> System.out.println ("Coucou")));
}
}
}
}
static private void clear_menu (final Menu menu)
{
for (final MenuItem menu_item : menu.getItems ())
{
final Menu child = menu_item.getMenu ();
if (child != null)
{
clear_menu (child);
}
menu_item.dispose ();
}
}
static private void dispose_menu (final Tree tree)
{
tree.getMenu ().dispose ();
final var menu = new Menu (tree);
menu.addMenuListener (MenuListener.menuShownAdapter (e -> build_menu (tree)));
tree.setMenu (menu);
}
} Best regards, |
Hello,
Issue description:
In a GUI application made with "Eclipse IDE for RCP and RAP Developers" on Linux Fedora 40, I have a menu attached to a tree. For one of the TreeItems, the menu has a very large number of MenuItems and consequently exceeds the screen height. For the next TreeItem, the menu has only four MenuItems. If I open and close the menus of these two TreeItems, the rendering of both is perfectly fine.
If I open the large menu then scroll inside it with the mouse to see off-screen MenuItems then close the large menu and then open the small menu next to it, the small menu is rendered as 4 four blank lines plus a top handle as if it was a menu exceeding the screen. If I scroll down long enough inside the small menu, the four expected MenuItems finally will appear, the top handle
is not shown any more and scrolling in the small menu has no effect any more.
I verified I can reproduce this issue against Eclipse Version: 2024-09 (4.33.0) Build id: 20240905-0614
I did not expect the small menu to be blank and to have to scroll inside it.
I understand reporting an issue to this OSS project does not mandate anyone to fix it. Other contributors may consider the issue, or not, at their own convenience. The most efficient way to get it fixed is that I fix it myself and contribute it back as a good quality patch to the project.
Best regards,
François
The text was updated successfully, but these errors were encountered: