JavaFX 2.0+--menu displays more than one screen scroll bar bug

Source: Internet
Author: User

Background

In JavaFX, menus can be scrolled when MenuBar's menu or its sub-menu contains more than the MenuItem a screen can display. There is a bug where scrolling is recorded, and all ContextMenu at the same level use the same scroll position, which means that when you scroll down more than a few distances in a contextmenu, Another contextmenu may not be able to see ContextMenu at all.

Analysis

The root cause of this bug is that different ContextMenu share the same scrolling position, so the different contextmenu should have their own scroll position records. You can find a way to see if the individual ContextMenu can maintain the scroll position alone, but I have no idea here.

My current plan is: When the menu is displayed, immediately reset the scroll position to 0, and by the way to hide the menu again to refresh, this scheme has a flaw is to leave the menu and then come back to scroll position is reset (this program is printed, debugging to see the level of class, refresh processing and other aspects of the investigation to find ...).

Code
//Correct the scroll bar position immediately after the menu is displayedCurmenu.setonshown (NewEventhandler<event>() {    Private BooleanFiredbyself =false;//used to identify whether a refresh is triggered by the scenario itself, or a refresh triggered by an external operation@Override Public voidhandle (Event t) {if(firedbyself) {firedbyself=false; return; }//find the most core display skin type ContextmenucontentContextMenu parentpopup = Curmenu.getitems (). Get (0). Getparentpopup (); FinalScene scene =Parentpopup.getscene (); Parent Root=Scene.getroot (); Group Group= (Group) root.getchildrenunmodifiable (). Get (0); Contextmenucontent content= (contextmenucontent) group.getchildren (). Get (0); Class CLA= Contextmenucontent.class; Try{//Modifying the scroll position by reflection-private variable TyField field; Field= Cla.getdeclaredfield ("Ty"); Field.setaccessible (true); Field.set (Content,0); //Refresh--Hide and showcurmenu.hide (); Firedbyself=true;        Curmenu.show (); } Catch(SecurityException ex) {Log.error ("", ex); } Catch(IllegalArgumentException ex) {Log.error ("", ex); } Catch(Illegalaccessexception ex) {Log.error ("", ex); } Catch(Nosuchfieldexception ex) {Log.error ("", ex); }    }});

Copy to Google TranslateTranslation Resultscontextmenucontent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.