Results 1 to 1 of 1
Thread: JAVAFX 2.0 popup menu
- 01-12-2012, 02:10 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
JAVAFX 2.0 popup menu
I'm no expert... but you might find this a help.....
Its not quite finished and I'm working on one that doesn't take up the screen .... not much different to this..
Any improvements welcome too.......
As the constructor I'm using a HBox with the content I want in the menu.

Java FX Code:package fyp_d07114915.Utilities; import javafx.animation.FadeTransition; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Bounds; import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.scene.layout.TilePane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.util.Duration; public class PopupMenu { Group group; StackPane stackpane = new StackPane(); Double MIN_HEIGHT = 60.0, MIN_WIDTH = 80.0; public PopupMenu(final Scene scene, final Node content) { this.group = (Group) scene.getRoot(); Button closeBtn = new Button("[X]"); closeBtn.setCancelButton(true); closeBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { closeMenu(); } }); Bounds boundsInParent = content.getBoundsInParent(); Double height = (boundsInParent.getHeight() < MIN_HEIGHT) ? MIN_HEIGHT : boundsInParent.getHeight(); Double width = (boundsInParent.getWidth() < MIN_WIDTH) ? MIN_WIDTH : boundsInParent.getWidth(); Rectangle outRectangle = new Rectangle(scene.getWidth() - 2, scene.getHeight() - 2); outRectangle.setOpacity(0.2); outRectangle.setFill(Color.BLACK); Rectangle inRectangle = new Rectangle(width + 20, height + 20, Color.WHITESMOKE); inRectangle.setArcHeight(10); inRectangle.setArcWidth(10); inRectangle.setOpacity(0.90); Rectangle borderRectangle = new Rectangle(inRectangle.getWidth() + 3, inRectangle.getHeight() + 3); borderRectangle.setArcHeight(10); borderRectangle.setArcWidth(10); borderRectangle.setOpacity(0.90); TilePane tile = new TilePane(Orientation.HORIZONTAL, 0, 10); tile.setTileAlignment(Pos.CENTER); tile.setPrefTileWidth(width); tile.getChildren().addAll(content, closeBtn); tile.setManaged(false); tile.relocate(scene.getWidth() / 2 - boundsInParent.getWidth() / 2, scene.getHeight() / 2 - boundsInParent.getHeight() / 2); TilePane.setAlignment(closeBtn, Pos.BASELINE_CENTER); stackpane.setAlignment(Pos.CENTER); stackpane.setPrefSize(outRectangle.getWidth(), outRectangle.getHeight()); stackpane.getChildren().addAll(outRectangle, borderRectangle, inRectangle, tile); } public void openMenu() { group.getChildren().add(stackpane); FadeTransition fadein = new FadeTransition(Duration.millis(500), stackpane); fadein.setFromValue(0.0); fadein.setToValue(1.0); fadein.play(); } public void closeMenu() { FadeTransition fadeout = new FadeTransition(Duration.millis(300), stackpane); fadeout.setFromValue(1.0); fadeout.setToValue(0.0); fadeout.play(); fadeout.setOnFinished(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { group.getChildren().remove(stackpane); } }); } }
Similar Threads
-
popup menu
By jperson in forum New To JavaReplies: 3Last Post: 09-18-2010, 01:44 PM -
tray popup menu
By newbiejava in forum New To JavaReplies: 1Last Post: 01-11-2010, 07:05 PM -
How can I add popUp menu on a tab of a tabbedPane?
By shahid0627 in forum AWT / SwingReplies: 1Last Post: 08-31-2009, 04:19 AM -
Regarding popup menu in netbeans IDE
By santhosh_el in forum AWT / SwingReplies: 2Last Post: 03-11-2009, 01:14 PM -
how to create Popup Menu with Sub Menu while right-clicking the JTree Node??
By Kabiraa in forum AWT / SwingReplies: 7Last Post: 05-09-2008, 07:54 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks