package bug; import com.sun.javafx.collections.ObservableListWrapper; import java.util.Arrays; import java.util.Iterator; import javafx.application.Application; import javafx.collections.ObservableList; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.control.MenuItem; import javafx.scene.control.SplitMenuButton; import javafx.scene.control.SplitMenuButtonBuilder; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class Bug extends Application { private Scene scene = null; private Button bLeft = null; private Button bRight = null; private SplitMenuButton node = null; public SplitMenuButton createControl() { SplitMenuButton smb = SplitMenuButtonBuilder.create() .text("Split box the first line" + "\nthe sec long line" + "\nthe third line") .items(new MenuItem("Split box the first line" + "\nthe sec long line" + "\nthe third line", new Rectangle(10, 10, Color.BLUE))) .graphic(new Rectangle(10, 10, Color.RED)) .build(); smb.setFocusTraversable(false); return smb; } public static String getFocus(Node node){ String result = ""; String temp = ""; if(node instanceof Parent){ Parent parent = (Parent)node; ObservableList childs = parent.getChildrenUnmodifiable(); if(!childs.isEmpty()){ Node cur = null; Iterator iter = childs.iterator(); while(iter.hasNext()){ cur = iter.next(); temp = getFocus(cur); if(!temp.equals("")){ result+=temp + " "; } } } if(node.isFocused()){ result += node.toString(); } } return result; } @Override public void start(Stage primaryStage) { node = createControl(); bLeft = new Button(); bRight = new Button(); bLeft.setText("Left"); bRight.setText("Right"); VBox root = new VBox(10); scene = new Scene(root, 300, 250); root.getChildren().addAll(bLeft, node, bRight); scene.setOnKeyReleased(new EventHandler(){ @Override public void handle(Event t) { //throw new UnsupportedOperationException("Not supported yet."); System.out.println(getFocus(scene.getRoot())); } }); primaryStage.setScene(scene); primaryStage.show(); } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, e.g., in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }