Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Define ContextMenu in FXML

917878Feb 16 2012 — edited Feb 21 2012
Hi All,

I am using javaFX 2.0.2 (with Netbeans 7.1).

I have not found plausible documentation on how to define ContextMenu in FXML file. I did find code samples using setContextmenu(), but no info howto convret it to FXML.

After several unsuccessful tries (even assigning the contextmenu to a control was not immediate) I found that the below fxml structure (at least) does not throw errors, but does not work either. I right mouse click the textfield and nothing happens.
<TextField text="OVERVIEW" style="-fx-padding: 5 5 5 5"
        GridPane.columnIndex="0" GridPane.rowIndex="0">
       <children>
            <ContextMenu fx:id="contextMenuDB">
                <items>
                    <MenuItem text="Import"
                                onAction="#ImportDB"/>
                    <MenuItem text="Export"
                                onAction="#ExportDB"/>
                    <MenuItem text="Report"
                                onAction="#CreateReport"/>
                </items>
            </ContextMenu>
      </children>
</TextField>
Is the <children> tag the right way or should I use some other tag instead?
Do I need to do anything (I mean coding) else than defining the contextmenu in FXML?

Thanks in advance for any comment.
This post has been answered by 885691 on Feb 20 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2012
Added on Feb 16 2012
6 comments
3,251 views