A GTK Toolbar can display an overflow menu when the toolbar is not wide enough to show its contents.
It seems that this feature doesn't work if the toolbar contains ComboBoxes wrapped by ToolItems.
Here is an example code that demonstrates the issue. It's written in Haskell but I guess it shouldn't be too difficult to translate it into other languages.
The instructions to build the repo is written in the README.md.
The last command opens a small GTK window. If you make it bigger you'll see two ComboBoxes in the window. The problem is that if you make the window narrower a bit, the right ComboBox disappears and no overflow menu appears even though toolbarShowArrow is enabled.
(Unfortunately I don't have enough reputation on SO to post two screenshots here so I uploaded them on the repo.)
Interestingly if I change the contents of the Toolbar from ToolItems to ToolButtons for example, I get the overflow menu.
Also I tested this with 3 packages: gtk for GTK2, gtk3 for GTK3, and gi-gtk for GTK3 with gobject introspection. All of them have the same issue.
So the question is: is there any workaround for this issue?
The documentation states this about gtk_toolbar_set_show_arrow():
Sets whether to show an overflow menu when toolbar doesn’t have room for all items on it. If TRUE, items that there are not room are available through an overflow menu.
So, it's an "overflow menu". I won't bore you with a detour into the GTK+ source, but suffice it to say: the items you add to the Toolbar need to provide menu items to appear in its overflow menu. Sounds logical now, right? :D
ToolButtons work because they call set_proxy_menu_item() with a MenuItem they create specifically for this purpose.
And that's what Toolbar looks for when deciding whether items can overflow: proxy MenuItems, which it can put into the overflow menu - and only if it finds at least one is there any point in giving the arrow to open that menu.
So, if you have other widgets, you can to get them into the overflow menu by setting a proxy menu item on your ToolItem, by either of:
simply calling gtk_tool_item_set_proxy_menu_item() to set a specific item
connecting to the ::create-menu-proxy signal on your ToolItem, and deciding during each emission whether or not to set (or clear) the proxy item
You'd also, of course, connect ::activate on that MenuItem to do something appropriate relating to the original ToolItem.
...though whether you can do anything useful from a MenuItem if the ultimate ToolItem child is a ComboBox is a different question. It doesn't expose its popup menu as something you can use. I guess you could just add a duplicate of the ComboBox to a MenuItem and use that as your proxy... But in that case, likely you're outwith the scope of what the overflow menu is meant for, and should instead just ensure your Toolbar doesn't get small enough to lose such controls.
Or maybe not! Try it and see how it goes.
Related
I have several commands added to an overflow menu.
When running the app, the overflow menu is scrollableY and has a scrollbar on the right. The effect looks kind of odd in my app.
I have tried to access the menu via hi.getToolbar(). ..., but there seems to be no method to get the overflow menu directly.
How can I turn the scroll effect and the scrollbar off in the overflow menu?
Thanks in advance for any kind help.
That sounds like something we should fix. We already did a similar fix for the side menu with the theme constant sideMenuScrollVisibleBool. We should probably disable the visibility of the scroll here by default too. This should be easy but due to the code freeze I can't do this right now.
Please file an issue and we'll try to address it after the release: http://github.com/codenameone/CodenameOne/issues/new
Is there any way to hide menu and search buttons from Kindle Fire? This (Kindle Fire Customize Soft Key menu) says there's no way to do that, but i hope something has changed since then.
Thanks!
The overflow menu is automatic and controlled by the OS (similar to the Action menu on devices based on the default Android experience). The search icon is fixed and will either take the user to the platform search or you can override it following the instructions here.
You may also be able to achieve the effect you are looking for with one of the Full Screen Modes available to Kindle developers.
Do you have a sample of the code that is failing to hide the overflow menu appropriately?
I am quite new in JavaFX and I have a question about the design. I am creating my main menu in FXML using Scene Builder. I have various menu buttons and each of these have a sub-menu. These sub-menu options will open new windows. Is it possible to declare these submenu choices so they do not dissapear after I click on them? If so, can I declare it in my fxml or I have to do it programatically?
Also, is it possible to detach it from the menu button? I would like to have my menu choices around 1 cm away from the menu button itself.
Thank you
Suggested Alternate Solution
If you want more flexibility in positioning a popup menu after a button click as well as fine control over when the menu shows and hides, try using a Button + a ContextMenu rather than a MenuButton.
The relevant methods are:
contextMenu.show(anchorNode, side, dx, dy)
contextMenu.hide()
There is sample code for triggering a context menu on a button press button in the ContextMenu javadoc.
You might also need to monitor the context menu's showingProperty and in a listener show the menu again if the JavaFX system has decided to try and hide it after some user action and you still want the menu visible.
Answers to additional unrelated comments
OK It sounds logical, yet since Im not really good in JavaFX yet, your Idea is quite challenging.
It's not that hard to implement, but from your subsequent comments it sounds like it's probably not the user interface you want for your users anyway (which makes sense to me because the interface you describe in your question seems a little strange).
I thought If it would be easier to have a static xml that have various menu choices, lets say aligned to the right and then whenever I click one of the choices, a new FXML would be loaded in the middle of the screen holding buttons for a submenu?
That seems logical. Sounds like a JavaFX version of a traditional web page layout with a navigation menu on the side controlling a content pane in the center.
A Java only version of that is: How to have menus in java desktop application. You could adapt that to a FXML based version without too much difficulty.
You might also be interested in Managing Multiple Screens in JavaFX.
Also, any tutorial for beginners would be greatly appreciated. These Oracle ones dont make too much sense for me
If you are beginning JavaFX, I recommend using just the Java API portions of JavaFX until you become familiar with them, and then use FXML only after you are comfortable with the Java API.
Personally, I think the Oracle JavaFX Tutorials are excellent. The difficulty for beginners is that the tutorials are also part reference material, which complicates portions of them (especially the deployment related pieces).
If you prefer a different tutorial style see:
Makery JavaFX tutorial (good for beginners)
zenjava tutorials (more advanced)
I am trying to apply custom menu to tab pages on my notebook control. I need to be able to select certain specific action for the entire page and i figured the tab label would be the best place to start.
So, i created a EventBox, applied Label as its child, and bound event callbacks to button-pressed-event and it... works.. kindof.
What i get is two menus: one is the one I create, and on top of it - the one created by GTK Notebook. to select something from my custom menu i need to escape the notebook menu first, and i certainly don't like it.
so the question is: how do I disable gtk notebook menus? or how can i set my own, custom menu, with my own, custom callbacks? I don't want to list all the available tab pages in the menu - it's introducing too much noise, so adding menu labels to the existing menu is not really the way to go.
thanks bunches
GtkNotebook should only show the tab selector if enable-popup is true. It defaults to false, so you've probably enabled it by mistake.
I am working on a Haskell application using gtk2hs. This application has a toolbar which consists of several GtkToggleToolButton, GtkToolButton and GtkToolItem elements. For being able to resize the applications window, I set the ShowArrow attribute to True, so that elements, that would be outside the window, are listed in an overflow menu.
This works fine for GtkToggleToolButton and GtkToolButton elements, but GtkToolItem elements do not show up in the menu. This would not be such a big problem, but if those elements are not inside the window frame, the menu arrow does not show up only for them. So that you have no indication that the toolbar has actually more elements.
The GtkToolItem contains a GtkTable which contains a label and two GtkToolButton elements. Can I tell GTK that it should display a label in the overflow menu for my GtkToolItem elements?
Thank you in advance!
Tobias
GtkToolButton itself is a GtkToolItem (and you can add that table to it)! Then why you are using GtkToolItem directly?
And I think you should use GtkToolButton.set_stock_id (or set_icon_widget) aditional to set_label, instead of createing a table...
ToolItem has a method toolItemSetProxyMenuItem which allows you to specify the menu item that is displayed in the overflow menu:
http://hackage.haskell.org/packages/archive/gtk/0.11.0/doc/html/Graphics-UI-Gtk-MenuComboToolbar-ToolItem.html#v:toolItemSetProxyMenuItem