alscu
alscu

Reputation: 928

ContextMenu not working on JavaFX2 TextArea?

This is not working for me, the context menu doesn't get displayed:

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 *
 * @author Alvaro
 */
public class TextAreaContextMenu extends Application {
    Group root = new Group();

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(root));
        TextArea t = new TextArea();
        ContextMenu m = new ContextMenu();
        m.setOnShowing(new EventHandler<WindowEvent>() {

            @Override
            public void handle(WindowEvent arg0) {
                System.out.println("Showing...");
            }
        });
        MenuItem item = new MenuItem("Item");
        m.getItems().add(item);
        t.setContextMenu(m);
        root.getChildren().add(t);  
        primaryStage.show();
    }

     public static void main(String[] args) {
        launch(args);
    }
}

Is this a bug? or am I doing something wrong? I'm running jdk1.7.0_02, and I think JavaFX 2.0.2 SDK. BTW, how do I find out, exactly which JavaFX SDK version I have installed?

Thanks in advance for any help.

Upvotes: 1

Views: 959

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34478

Your code works for me with JavaFX 2.1 dev build on Windows. Right-click on text area shows menu with one element named "item".

Can you try 2.1 dev version?

You can find out your current version by running next code:

        System.out.println(com.sun.javafx.runtime.VersionInfo.getVersion());

Upvotes: 1

Related Questions