RFR: 8353599: TabPaneSkin: add 'menuGraphicFactory' property [v7]
Ambarish Rapte
arapte at openjdk.org
Wed Sep 24 12:46:10 UTC 2025
On Wed, 17 Sep 2025 19:55:26 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>> Tries to address the mystery of missing graphic in the TabPane overflow menu.
>>
>> ### Summary of Changes
>>
>> - minor `TabPaneSkin` constructor javadoc clarification
>> - added the property
>> - changed popup menu to be created on demand
>> - removing adding the popup reference to the `TabHeaderSkin` properties (I think it was done for testing purposes, I could not find any references to it in the code)
>>
>> For a quick tester, use https://bugs.openjdk.org/secure/attachment/114240/TabPaneGraphicFactoryExample.java
>>
>> # Overflow Menu Graphic Property in the TabPaneSkin
>>
>> Andy Goryachev
>>
>> <andy.goryachev at oracle.com>
>>
>>
>> ## Summary
>>
>> Introduce a `menuGraphicFactory` property in the `TabPaneSkin` class eliminates the current limitation of this skin
>> in supporting menu item graphics other than an `ImageView` or `Label` with an `ImageView` graphic.
>>
>>
>>
>> ## Goals
>>
>> The goals of this proposal are:
>>
>> - to allow the application developers to customize the overflow menu items' graphic
>> - retain the backward compatibility with the existing application code
>> - clarify the behavior of the skin when the property is null (i.e. the current behavior)
>>
>>
>>
>> ## Non-Goals
>>
>> The following are not the goals of this proposal:
>>
>> - disable the overflow menu
>> - configure overflow menu graphic property via CSS
>> - add this property to the `TabPane` control itself
>>
>>
>>
>> ## Motivation
>>
>> The existing `TabPaneSkin` does not allow the overflow menu to show graphic other than
>> an `ImageView` or `Label` with an `ImageView`.
>>
>> This limitation makes it impossible for the application developer to use other graphic Nodes,
>> such as `Path` or `Canvas`, or in fact any other types. The situation becomes even more egregious
>> when the tabs in the `TabPane` have no text.
>>
>> Example:
>>
>>
>> public class TabPaneGraphicFactoryExample {
>> public void example() {
>> Tab tab1 = new Tab("Tab1");
>> tab1.setGraphic(createGraphic(tab1));
>>
>> Tab tab2 = new Tab("Tab2");
>> tab2.setGraphic(createGraphic(tab2));
>>
>> TabPane tabPane = new TabPane();
>> tabPane.getTabs().addAll(tab1, tab2);
>>
>> TabPaneSkin skin = new TabPaneSkin(tabPane);
>> // set overflow menu factory with the same method as was used to create the tabs
>> skin.setMenuGraphicFactory(this::createGraphic);
>> tabPane.setSkin(skin);
>> }
>>
>> // creates graphic Nodes for tabs as well as the overflow menu
> ...
>
> Andy Goryachev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 11 additional commits since the last revision:
>
> - Merge remote-tracking branch 'origin/master' into 8353599.menu.factory
> - Merge branch 'master' into 8353599.menu.factory
> - Merge branch 'master' into 8353599.menu.factory
> - Merge branch 'master' into 8353599.menu.factory
> - Merge remote-tracking branch 'origin/master' into 8353599.menu.factory
> - popup menu on demand
> - Merge remote-tracking branch 'origin/master' into 8353599.menu.factory
> - Merge remote-tracking branch 'origin/master' into 8353599.menu.factory
> - javadoc
> - Merge remote-tracking branch 'origin/master' into 8353599.menu.factory
> - ... and 1 more: https://git.openjdk.org/jfx/compare/1a67c5b4...2e8848ef
With this change, For a same tab the graphic in TabHeader and graphic in overflow menu can be different.
Here is a screenshot from modified version of the sample program.
<img width="308" height="364" alt="Screenshot 2025-09-24 at 18 04 50" src="https://github.com/user-attachments/assets/6494aca1-06ac-4aaf-a405-f6e55f5823ae" />
Of course it is in programmer's control.
But, can we fix on a behavior that if a graphic is set on a tab, then the same graphic would be used in overflow menu and a graphic from menuGraphicFactory will be neglected ?
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1773#issuecomment-3328237848
More information about the openjfx-dev
mailing list