Different context menu for every TreeView Node - javafx

I created context menu for TreeView Node but I face a problem how I can create context menu for different tree nodes?
Is there any way to solve this?

See https://www.marshall.edu/genomicjava/2013/12/30/javafx-tableviews-with-contextmenus/ which does something similar for TableViews. You can adapt the ideas there to work with a TreeView.

You can define a custom TreeCell factory on your TreeView. This custom factory will build a custom TreeCell, and, this custom cell can define the context menu as expected.
This answer shows how to create these custom pieces of building blocks :-).

Related

Should children of a ContentPage be rendered too when using a custom renderer?

I’ve been using Xamarin.Forms for a bit lately and can generally get enough information following the Microsoft docs. But I seem to be stuck now that I need to create a custom renderer, so if someone could help, I’d really appreciate.
I read through the docs on creating a custom render and maybe I missed the part I’m looking for, but I’m not able to tell if as part of OnElementChanged, I also need to render all the children of the Element?
The ContentPage could have a StackLayout for example with several child elements. If I dont have to render these, how do they get rendered/laid-out?
No, you don't need to render ContentPage's children.
When you create a Custom Renderer you are only extending Xamarin's renderer, meaning you only add functionality (unless you explicitly change something, like redefining a property).
So, basically, the ContentPage render/lay-out the children the same way it renders/lays-out without the Custom Renderer.
Answering your second question, actually the layout and positioning is done without renderers, as said here Xamarin.Forms Layouts.
If you want to dig deeper, you can try to understand how the ContentView (it's the easier one) is positioned by reading the source code. Here the TemplatedView (ContentView's base class) is calling LayoutChildIntoBoundingRegion for each of its children: TemplatedView.
Then this line on the LayoutChildIntoBoundingRegion calls the Layout method of the view: Layout.
The VisualElement.Layout method only gets the rectangle and sets the Bounds of the view (Layout Method). The Bounds setter is called: Setter.
Well, now you can go on and explore more of the source code if you want, but I think you got the idea ;)
Hope it helps!

JavaFX nodes - How to make them resizable by the end user?

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.
Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.
The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.
However, I have failed to find out how I can make these nodes resizable by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter what the OS.
Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)
Many thanks,
Ian.
As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.
The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.
I found something that you can use : Dragging to resize a JavaFX Region
This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :
Only height resizing is currently implemented.
This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8
Hope this helps.

Flex: Custom context menu for a component

I have a Flex application, running with Flash Player, not AIR, that contains a Tree that I would like to put a custom context menu on.
Tried just doing <mx:Tree ... contextMenu="{MyClassWithStatic.menu}">, but that didn't do anything.
Went searching, and found this quote from some Adobe docs somewhere
In Flex or Flash Builder, only top-level components in the application can have context menus. For example, if a DataGrid control is a child of a TabNavigator or VBox container, the DataGrid control cannot have its own context menu.
so went upwards, trying each parent element until I reached my <Application>-element, which is consistent with what they wrote.
Tried making a Flex component, based on Group (the default) which contained my tree, and the context menu on the top-level element there, hoping it would work, but to no avail.
Is there any other way to manage this that I haven't found yet?
The code I use to create the menu:
var menuItems:Array = [];
var rename:ContextMenuItem = new ContextMenuItem("Rename");
rename.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, renameSelectedHandler);
menuItems.push(rename);
menu.customItems = menuItems;
menu.hideBuiltInItems();
You're right, the contextmenu only works on top level components. It's a limitation of Flex which is annoying and shouldn't be there in the first place. There's not much you can do since there is no way to capture the event other than using some Javascript trickery, but even then, it doesn't tell you where you were clicking.
If I were you, I would just forget the concept and go away from using right click altogether if possible.
I can't be sure, as all the code isn't' there. But you seem to have ignored your own research. Don't use your new component, or anything which "contains" your tree. Then just stick the Tree in your application.
Also I've a memory of TreeItemRenderer not being the same as in other UIcomponents. Maybe, test your "menu" code with a Datagrid first and make sure it works. Good luck
I did not try it myself, but after reading the comments on http://michael.omnicypher.com/2007/02/flex-trees-with-context-menu_14.html it looks like you could add a context menu to the tree's item renderer.
The article and comments at http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/ are worth a look too.

How to add custom component in context menu of datagrid

How to add custom component in context menu of datagrid.Here custom component like one text box with formatting details.
You cannot put components into the context menu. You can only have menuitems that dispatch a menuclick event. Unfortunately the context menu in the flashplayer is lacking a lot of functionality like that.
You might be able to highjack the context menu all together and display some sort of title window on a right click, but I am not sure if this is possible or how you would go about trying to achieve it.

Flex ContextMenu Change the items dynamically

I am using a ContextMenu for an AdvancedDataGrid in my application. I could implement the normal context menu for the grid. Now, I am planning to make the context menu dynamic.
For example, if I click on a particular cell, I need to see only the items related to that cell in the Context Menu. Is there any way we can do that?
ContextMenu class contains a customItems property which is (quoting from Adobe livedocs):
An array of ContextMenuItem objects. Each object in the array represents a context menu item that you have defined. Use this property to add, remove, or modify these custom menu items.
To add new menu items, you create a ContextMenuItem object and then add it to the customItems array (for example, by using Array.push()). For more information about creating menu items, see the ContextMenuItem class entry.
I found the solution for this. Quite simple:
http://www.pubbs.net/flex/200905/73331/

Resources