-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[0.7] Contextmenu not supported by : org.fxmisc.richtext.CodeArea #363
Comments
Just a guess, but I think this is because |
@JordanMartinez yeah, you're right. but any idea how to implement it? |
@JordanMartinez , I did it like this in
Here is context-menu.css
area is instance of GenericStyledArea. Hope it helps. |
@rivagti See @nazmuddin's example in combination with mine below. He uses a package org.fxmisc.richtext.demo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextArea;
import org.fxmisc.wellbehaved.event.EventPattern;
import org.fxmisc.wellbehaved.event.InputMap;
import org.fxmisc.wellbehaved.event.Nodes;
public class ContextMenuExample extends Application {
@Override
public void start(Stage primaryStage) {
// create your context menu somewhere in your code...
ContextMenu menu = new ContextMenu();
menu.getItems().addAll(
new MenuItem("Menu 1"),
new MenuItem("Menu 2"),
new MenuItem("Menu 3")
);
InlineCssTextArea area = new InlineCssTextArea("Some text");
// add an input mapping that shows that context menu when you
// right click somewhere in the area
Nodes.addInputMap(area,
InputMap.consume(
EventPattern.mouseClicked(MouseButton.SECONDARY),
e -> {
// show the area using the mouse event's screen x & y values
menu.show(area, e.getScreenX(), e.getScreenY());
}
)
);
primaryStage.setScene(new Scene(area, 500, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} |
Should this feature be supported out-of-box? private ContextMenu contextMenu = null
public final Optional<ContextMenu> getContextMenu() {
return Optional.ofNullable(contextMenu);
}
public final void setContextMenu(ContextMenu menu) {
contextMenu = menu;
}
private double contextMenuOffsetX;
public final double getContextMenuOffsetX() { return contextMenuOffsetX; }
public final void setContextMenuOffsetX(double xOffset) { contextMenuOffsetX = xOffset; }
// same for yOffset and add this handler to InputMapTemplate.consumeUnless(
mouseClicked(SECONDARY),
() -> !area.getContextMenu().isPresent(),
e -> {
double xOffset = area.getContextMenuOffsetX();
double yOffset = area.getContextMenuOffsetY();
area.getContextMenu().show(area, e.getScreenX() + xOffset, e.getScreenY() + yOffset);
}
} |
@JordanMartinez yes, I think so. anyway thank you both... @nazmuddin |
I ended up here after searching for how to get this working in 0.7, so +1 for supporting this out the box (especially since it's a feature regression from 0.6 otherwise.) |
Closed by #439. |
Hi,
Since i use the 0.7 the property ContextMenu isn't recognized, whereas it works on 0.6. Do i have any way to fix it, or any altrenative ?
The text was updated successfully, but these errors were encountered: