Changes in Scene + TreeItem + Focus

In my application, I frequently change the contents of a BorderPane or other container to switch between various views. These new views often need to get the focus (for easy keyboard control).
I've found however that when this involves a TreeView where I want the first item to have the focus that this is not working properly, see this example:
public class TreeItemFocusTest extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  @Override
  public void start(Stage primaryStage) throws Exception {
    VBox vbox = new VBox();
    BorderPane borderPane = new BorderPane();
    Button button = new Button("Sometihng to grab focus");
    final TreeView<String> treeView = new TreeView<String>();
    TreeItem<String> root = new TreeItem<String>("Root");
    root.setExpanded(true);
    treeView.setRoot(root);
    root.getChildren().add(new TreeItem<String>("Item 1"));
    root.getChildren().add(new TreeItem<String>("Item 2"));
    root.getChildren().add(new TreeItem<String>("Item 3"));
    root.getChildren().add(new TreeItem<String>("Item 4"));
    vbox.getChildren().addAll(button, treeView);
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.show();
    // Change the borderpane contents here
    borderPane.setCenter(vbox);
    // Give desired item the focus
    treeView.requestFocus();
    treeView.getFocusModel().focus(1);
}The TreeView itself gets the focus, but the TreeItem #1 does not get the focus.
I've found two work-arounds (that will give TreeItem #1 the focus as expected) :
1) Always replace the entire scene
2) Wrap the focus calls in Platform.runLater()
Neither seems to be the correct behaviour to me. Anyone care to comment or knows of a better solution?

Submitted as bug: http://javafx-jira.kenai.com/browse/RT-19633

Similar Messages

  • How do I move an object from one photo to another and then change the scene, i.e.  winter to sum?

    How do I move an object from one photo to another and then change the scene, i.e.  winter to summer?

    OK.
    Open the picture with the new scene. This will be your canvas.
    Open the picture with object A, select it with one of the selection tools, go to Edit>copy
    Go back to the new scene/canvas, Go to Edit>paste
    Repeat for object B
    Use the move tool to position A & B, each on its own layer. Use the corner handles of the bounding box to resize, if necessary
    You should have 3 layers: Background layer, and the 2 layers with A & B
    Note: It's best if the resolution of the 3 picture files is the same value.

  • How to change the scene from an external class?

    I'm trying to change the scene (gotoAndPlay(1,"secondScene")) from an external as3 class from flash professional, but I can't. I also tried root.gotoAndPlay(1,"secondScene") and stage.gotoAndPlay(1,"secondScene"). What is the better way to do it?
    Thank you.

    Its crucial that if you want to access root or the displaylist in general that an instance of your class is added to the displaylist as child. This is achieved by sth like:
    var _myClass:myClass = new myClass();
    addChild(_myClass);
    only then you will be able to reach root
    your class also has to met certain conditions: it must at least extend DisplayObject but its common that it extends MovieClip.
    so a basic class should look sth like this:
    package  {
        import flash.display.MovieClip;
        public class myClass extends MovieClip {
            public function myClass() {
                // constructor code

  • N73 camera, changing default scene to user defined...

    n73 manual says that AUTO scene is default but user can make USER DEFINED scene to be default. how can I do that?
    every time I start camera, there is AUTO scene.

    I think is not possible. Is like that.

  • Keeping the audio flow, but changing video scenes

    Okay, so I did an interview of sorts. A friend sitting by a window. As he speaks, I want to fade out of one scene and into another, then another, and so on. the back to him.. then fad out into another scenes. but keep the audio in sink so when I go back to him... for some reason I cant seem to insert a new scene without disrupting the audio. Thanks.

    Yes, what I gave you will work. Let me describe what these steps do in another way and see if you agree. The scenario, you have 20 minutes in one long clip of a person reading news just like watching TV. Five minutes in they read a story about Cuba, while the long clip continues, temporarily the view of the person reading is replaced by a map image though you still hear audio and when the map "cutaway" is over the 20 min. clip is just continuing unabated. There's no limit (I know of) to adding cutaways throughout the 20 minute video.
    Note that you do have to have Advanced Options enabled to do this, Preferences>General: Show Advanced Tools

  • How can I change where an applet focuses its view

    I'm writing a scrolling marquee applet and in order to scroll up, out of sight or scroll Left out of sight, I have to be able to draw my strings with negative x & y values which seem to not be allowed.
    I figure if I draw my marquee with the upper left corner located at around 300, 50, (instead of 0,0 ) I won't have to worry about drawing to negative coordinates.
    Is there anyway to set the applet so that when it opens in a browser, the upper left hand corner of the visible applet would begin at 300, 50 instead of 0, 0, by default?
    Charlene English

    when the text is at 0,0... it is still in view of the user. 0,0 is, so far, the extreme upper right hand corner of the scrolling marquee. If I wanted the text to scroll off screen to the left, I would have to start assigning negative values to the x component of drawString. This is the reason I want to offset the whole marquee by 300, 50. My Marquee is 350, 30 in size, so if I offset my Marquee without being able to control the view of the applet, I'd have an applet on my page (650, 80) in size and the marquee would be in the lower right hand corner.
    What I'm shooting for is an applet that is (350, 30) in size with it's upper left hand corner located at 300, 50.
    -Charlene

  • Some questions about how to change scenes

    i have something like the following:
    fxml (view/main/MainMenu.fxml):
    <Scene fx:controller="view.main.CtrlMainMenu" xmlns:fx="http://javafx.com/fxml" stylesheets="view/main/main.css">
        <GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" id="backgorund" hgap="10" vgap="10">
            <!--other panes -->
            <VBox spacing="8" GridPane.columnIndex="0" GridPane.rowIndex="1">
                <Button text="Start" onAction="#Start"/>
                <Button text="Options" onAction="#Options"/>
                <Button text="Exit" onAction="#Exit"/>
            </VBox>
        </GridPane>
    </Scene>main loop (cotroller/main.java):
    public class main extends Application{
        public static void main(String[] args){
            launch(main.class, args);
        public void start(Stage stage) throws Exception{
            stage.setTitle(CtrlLanguage.get(CtrlLanguage.TITLE));
            CtrlMainMenu main = new CtrlMainMenu();
            Scene scene = main.main();          //don't know how to make Scene scene = (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml")); work on here since MainMenu.fxml is in view/main while the main class is in controller and ended up putting CtrlMainMenu in the view although is not very correct
            stage.setScene(scene);
            stage.setWidth(1080);
            stage.setHeight(720);
            stage.show();
    }view controller (view/main/CtrlMainMenu.java):
    public class CtrlMainMenu{
        //other buttons actions
        public Scene main() throws Exception{
            return (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
        @FXML protected void Start(ActionEvent event){
        @FXML protected void Options(ActionEvent event){
        @FXML protected void Exit(ActionEvent event){
            System.exit(0);          //is there any other way to finish the program than using a system.exit?
    }got few questions currently:
    1. i'd like to be able to keep using CtrlMainMenu for other buttons while the ones that appear there go to the main (since will be reusing those classes from other scenes)
    tried adding fx:controller on panes instead of the scene, but it doesnt work at all (it crashes) else directly in CtrlMainMenu change the scenes of the stage, but then, i have to send the stage to every controller i use? (or how do i know the stage of the scene?)
    and in the case of options, i'd like after done, go back to the previous scene, is that possible? if so, how?
    2.if i want to implement languages, how do i do to change the text? tried with setText() but depending on where do i put it, it crashes, so dont know where do i have to put it
    3.im doing a game that may have different number of players, so, is there some way to erase/hide/add data from a gridpane with fxml?

    1. ok, found the way to change scenes, with this way:
    @FXML protected void Start(ActionEvent event) throws Exception{
         Node node = (Node)event.getSource();
         Stage stage = (Stage)node.getScene().getWindow();
         Scene scene = (Scene)FXMLLoader.load(getClass().getResource("../view/main/MainMenu.fxml"));     //this is just an example, will change to go to another scene
         stage.setScene(scene);
         stage.show();
    }but now i have another problem, when i click on the button the stage scene is changed, but the scene is transformed to a very small one at the top left (the size seems the same as when i dont put the set width/height on the stage when creating it), the stage size remains the same, and when i resize the window, it gets "repaired"
    the options, i thought on using a pane over the current pane so this way instead of going back would be just removing that new pane, would that work well?
    2. found about languages that is by using <Label text="%myText"/> and java.util.ResourceBundle but don't know how to use it, can someone provide me an example, please?
    3. still haven't looked on it...

  • Javafx: How change color of focus of controls?

    Hi everyone,
    I got a trouble with change the color of focus of controls? Have anyone know? Please tell me. Here is my example.
    [http://imageshack.us/photo/my-images/864/fffd.png/]
    Please help me out. Thank very much.
    Edited by: 904388 on Dec 25, 2011 7:45 AM

    Hi,
    The desired functionality can be acheived by customising the css of the text field. (or any control)
    Suppose if the textfield/button declaration is like this.,
    TextField text = new TextField();
    Button btn = new Button();It's related focus css is as follows (in caspian.css file)
    .text-field:focused {
        -fx-background-color: -fx-focus-color, -fx-text-box-border, -fx-control-inner-background;
        -fx-background-insets: -0.4, 1, 2;
        -fx-background-radius: 3.4, 2, 2;
    .button:focused {
        -fx-color: -fx-focused-base;
        -fx-background-color: -fx-focus-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
        -fx-background-insets: -1.4, 0, 1, 2;
        -fx-background-radius:  6.4, 5, 4, 3;
    }To customize the focus color, you need to define a custom class for your controls, like
    TextField text = new TextField();
    text.setStyleClass().add("myText");
    Button btn = new Button();
    btn.setStyleClass().add("myButton");and need to add the css accordingly for your focus color.
    .myText:focused {
        -fx-background-color: #E99725, -fx-text-box-border, -fx-control-inner-background;
    .button:focused {
        -fx-background-color: #E99725, -fx-outer-border, -fx-inner-border, -fx-body-color;
    }I hope the above explanation will help you.
    Happy Coding !! :)
    Regards,
    Sai Pradeep Dandem.
    Edited by: Sai Pradeep Dandem on Dec 26, 2011 8:58 PM

  • Change scene in scene graph

    I'm writing a game with JavaFX. For the different screens I decided to implement them as different Scenes, so clicking on an action would swap the scene in the application.
    The initial scene is naturally attached to the scene graph. Any scene that is later replacing the scene in the scene graph is not. When swapping it in, certain layouting for the scene is not done.
    While I know how to circumvent this (by calling the additional layouting methods, which are bound to the scene size change, when swapping), there are some things that I would like to understand:
    Is there a better way to do this?
    Is there a method on the scene that could be called to force the proper layouting
    Why does the scene only change initially when attaching it to the scene graph before showing it, but not when changing the scene at runtime?

    This looks like RT-30392. It is fixed in JavaFX 8.
    Another way to approach this is to use a single scene, and change the contents of the scene by calling setRoot(...). This works around the bug; I also usually find this approach a little cleaner as you only need access to the Scene, not to the stage.

  • How to change scene graph from listener thread?

    Greetings,
    I need a little help with javafx.concurrency.Task - I think.
    I have a JavaFX program that is listening for JMX Notifications. When I receive certain notifications, I want to change the scene graph. Of course, the notifications are being received on a thread kicked off by RMI, not the JavaFX Application thread -- so anything I try to do to the scene graph there won't work.
    I've look at Richard Bair's article: http://fxexperience.com/2011/07/worker-threading-in-javafx-2-0/
    and other examples, but every example I've found involves kicking off the Task from the Application thread and observing some property of the Task.
    I think I somehow need by Notification listener to queue up the things that need to be done to the scene graph somewhere, and then have a thread started from the Application thread read the queue and actually make the changes.
    I could use a pointer to an example, or even a general overview of how this type of thing should be accomplished. I could post a code example if needed, but it will take some doing and it wouldn't even be working.
    Thanks,
    Cameron

    Tasks/Service are most useful when you are initiating the action via the GUI (i.e. as a result of a button press, a mouse event, a keyboard action, etc). In your case JMX/RMI will be running an internal 'listener' thread which is triggering your handler method. In this case the best option is to just use Platform.runLater.
    Something like the following"
    {code}
    public void handleEventFromServer(final MyData dataFromServer)
    Platform.runLater(new Runnable() {
    public void run()
    // this will be done in your GUI thread so you can update the GUI here
    myTextField.setText("Result from server is: " + dataFromServer.getSomeValue());
    {code}
    If you have some sort of JmxListener interface you could just create a ThreadSafe event propagator like so:
    {code}
    public class ThreadSafeJmxListener implements JmxListener
    private JmxListener actualListener;
    public ThreadSafeJmxListener(JmxListener actualListener)
    this.actualListener = actualListener;
    @Override
    public void handleJmxEvent(final JmxEvent event)
    Platform.runLater(new Runnable() {
    public void run()
    actualListener.handleJmxEvent(event);
    {code}
    Then just use it something like so:
    {code}
    jmxChannel.addJmxListener(new ThreadSafeJmxListener(new JmxHandler()
    public void handleJmxEvent(final JmxEvent event)
    // this will be done in your GUI thread so you can update the GUI here
    myTextField.setText("Result from server is: " + dataFromServer.getSomeValue());
    {code}
    If you want to send data to the server, use a task (or service) for that. If you need more info on that, post back, but there is a fair bit of that in this forum, or on various blogs (you'll find a fair few examples buried in my posts: http://zenjava.com).

  • How to focus a range?

    Sorry if my english is not perfect!
    Is it possible to focus a range, so everything inside that range is 100% focused?
    Like the second image, where everything between the red lines would be 100% focused... is that possible? how?
    Thank you very much!

    You can change the apparent depth of field by adjusting the aperture of the camera in the same way you control the depth of field with a real camera. Depth of field is controlled by the ratio of the distance from the camera the focus point and the aperture. The bigger the aperture the shorter the depth of field. Fortunately AE's camera is not sensitive to light so you can use as small an aperture as you'd like. An aperture value of 0 will put everything in the scene in focus.
    There is however, no way of seeing the depth of field as an overlay so you have to just put objects in your 3D scene and adjust the camera position and aperture to get the results you want. AE's camera will essentially mimic a real camera so you can achieve the results you want.

  • Popup - how to get the focus in a specific compent

    Hi,
    I am trying to get the focus of my pop-up in the second component.
    Use case: New button in the table shows a popup to get the input from the user. There is a Undo Edit link (top-left) to discard changes, on top of the pop-up so by default the focus goes to the top left. I have input text boxes under that. And I am trying to get the focus (mouse cursor) in the first input text box rather than the undo Edit link. Any idea to implement that without using javascript ?
              <af:popup id="newPopup" contentDelivery="lazyUncached"
                        popupCanceledListener="#{commonUtils.CreatePopupCanceledListener}">
                <af:dialog id="createPopupDL" type="none"
                           title="#{viewcontrollerBundle.NEW_COURSE_PLAN_STRUCTURE_QUALIFIER_HEADER}"
                           resize="on">
                  <af:separator id="s1"/>
                  <af:panelGroupLayout id="pgl2" layout="vertical" halign="left">
                    <af:panelGroupLayout id="pgl3" layout="horizontal">
                        <!-- csc:undoEdit is a custom component to undo change
                        By default the focus is coming to this component -->
                      <csc:undoEdit id="ue1"/>
                    </af:panelGroupLayout>
                    <af:messages id="m1"/>
                    <af:spacer width="10" height="10" id="s2"/>
                    <af:panelFormLayout id="pfl1" labelAlignment="start"
                                        labelWidth="140">
                      <af:spacer width="10" height="10" id="s3"/>
                          <!-- I want to get my mouse cursor in this box -->
                          <af:inputText id="it2"
                                    label="#{bindings.QualifierCd.hints.label}"
                                    value="#{bindings.QualifierCd.inputValue}"
                                    showRequired="true"
                                    required="#{bindings.QualifierCd.hints.mandatory}"
                                    columns="#{bindings.QualifierCd.hints.displayWidth}"
                                    maximumLength="#{bindings.QualifierCd.hints.precision}"
                                    shortDesc="#{bindings.QualifierCd.hints.tooltip}"
                                    autoSubmit="true">
                        <f:validator binding="#{bindings.QualifierCd.validator}"/>
                      </af:inputText>
                    </af:panelFormLayout>
                  </af:panelGroupLayout>
                  <af:spacer width="10" height="10" id="s4"/>
                  <af:separator id="s5"/>
                  <f:facet name="buttonBar">
                    <af:group id="g2">
                      <af:panelGroupLayout id="pgl4" layout="horizontal"
                                           halign="start">
                        <af:commandButton text="#{smsCommonViewBundle.CreateBtn}"
                                          id="createCB" action="doCommit"
                                          partialSubmit="true"
                                          accessKey="#{smsCommonViewBundle.CREATE_ACCESS_KEY}">
                          <f:actionListener type="au.com.callista.sms.framework.view.lifecycle.PopupDismissActionListener"/>
                        </af:commandButton>
                        <af:spacer width="10" height="10" id="s6"/>
                        <af:commandLink text="#{smsCommonViewBundle.CANCEL_LNK}"
                                        id="cancelCL" action="doCancel"
                                        accessKey="#{smsCommonViewBundle.CANCEL_ACCESS_KEY}"
                                        immediate="true">
                          <f:actionListener type="au.com.callista.sms.framework.view.lifecycle.PopupDismissActionListener"/>
                          <af:resetActionListener/>
                        </af:commandLink>
                        <af:spacer width="400" height="10" id="s9"/>
                        <af:icon name="required" id="i1"/>
                        <af:spacer id="sp3" width="5" height="0"/>
                        <af:outputText value="#{smsCommonViewBundle.requiredLbl}"
                                       id="ot1" styleClass="requiredText"/>
                      </af:panelGroupLayout>
                    </af:group>
                  </f:facet>
                </af:dialog>
              </af:popup> Edited by: user9319679 on Sep 6, 2011 10:43 AM

    I dont think so that possible without javascript.. AFAIK
    <af:clientListener method="setFocus()" type="load"/>
          <af:resource type="javascript">
               function setFocus(event){
                 var input1 = document.getElementById('pt1:r1:3:pt1:it1::content'); // the complete id of the inputText - change it according to your jsff.. use firebug to get the proper id
                 if(input1!=null)
                 {input1.focus();
          </af:resource>

  • Firefox 4 download. Since, Windows start button options changed. Should be browser agnostic, can you please tell me how to fix this? While I love Firefox, this has me livid! (1 irony, Firfox is no longer in my Start button menu.)

    I first noticed an issue when looking for something normally located in the Accessories folder of MS programs. What I found upon clicking on "All Programs" was not the program file/folder tree I expected but rather a direct list of all files in the Program Files folder. I then went to open a new session of Firefox to research that issue and noticed my basic Start button options were also changed. Now, even focus for event-driven events is not working correctly. Again, while I love Firefox, this needs to be fixed immediately or I will be forced to uninstall the product just to function.

    Unfortunately I tried that and it didn't work. Thanks for the help though. I tried to uninstall and it said I couldn't because the file is corrupt or something, but I think I finally got it uninstalled and/or deleted or whatever, but now I try to reinstall/download it again from the beginning and I can't. No matter what I do I can not get Firefox working again. No matter how many times I try to redownload it. Any other suggestions?

  • How can I display a new scene in JavaFX 2.2? For example after button click

    how to display new scene after button click in the main window, I want the main window and the new scene are in one stage. thx

    You can change the scene by calling stage.setScene(new Scene(newContentParent));
    I don't think you are quite asking for a complete scene change though as you "want the main window and the scene in one stage". The main window is a stage (as Stage extends Window). And a given stage can only contain one scene at a time (though you can swap it out by calling setScene as described earlier).
    What I think you are really asking for how can you replace some content part of the active Scene on the Stage. To do that you can set a layout manager like a HBox or a BorderPane as the root of your scene, then change out the content of the layout manager. For example:
    final BorderPane layout = new BorderPane();
    layout.setCenter(new Label("Dogbert");
    final Button nav = new Button("Next");
    layout.setLeft(nav);
    nav.setOnAction(new EventHandler<ActionEvent>() {
      @Override public void handle(ActionEvent actionEvent) {
        layout.setCenter(new Label("Dilbert"));       
    });In the above short sample code, if you wanted to change the scene rather than the a pane, then you would call stage.setScene rather than layout.setCenter.
    There is a complete executable example with multiple content panes and some styling here:
    http://stackoverflow.com/questions/13556637/how-to-have-menus-in-java-desktop-application

  • Can I add the same style sheet to multiple nodes in the same scene?

    I know this sounds like a dumb question, so I'll give an explanation below.  I've done this with FXML and Scene Builder and haven't noticed any negative effects yet.  I'm mostly curious what happens internally when I add a style sheet to a node and that same style sheet has already been added via a parent node.
    The reason I ask is because I use fx:include in many of my FXML files.  For example, I'll have something like this:
    MainPane.fxml - Uses shared.css and main-pane.css.  Includes SubPane.fxml.
    SubPane.fxml - Uses shared.css and sub-pane.css.  Included in MainPane.fxml using fx:include.
    I used to add shared.css to SubPane.fxml using Scene Builder's preview option, but the way this works has been changed in Scene Builder 2.  See this thread for an explanation of the change.  I also use TestFX and I'm convinced that I should be ensuring shared.css is applied to SubPane.fxml before running GUI tests.
    The easiest way to accomplish what I want is to add shared.css to the root node of both MainPane.fxml and SubPane.fxml.  However, I don't know if that's something I'm allowed to do.  Is it?

    No. http://www.adobe.com/products/creativecloud/faq.html
    Can I buy more than one membership to an individual offering of Creative Cloud? 
    No, Adobe has moved to identity-based licensing with a technology that will not support multiple same-product licenses, so you can buy only one membership per Adobe ID. If you need two Creative Cloud memberships, you will need to purchase each with a unique Adobe ID. You can also purchase a Creative Cloud for teams membership, which allows you to purchase and manage multiple seats under one account.

Maybe you are looking for

  • Install Windows 8 on Pavilion 20

    Hi I have a Pavilion 20 that stuck on HP logo, so I need to reinstall Window 8. How can I do it?

  • Software problem with 30 gig video ipod and itunes 7?

    ok ever since ive had my ipod it works nice now. since ive moved over to itunes 7 its messed up the first time, it didnt even update the software all the way and i had to restore it manually cuz i had 2 softwares on my iod. also when i ejected and pl

  • Exporting Highlighted Text from a PDF

    I'm creating a publication in Indesign, a pdf of each chapter being reviewed by its author, usually highlighting "keywords". I need to be able to export text "highlighted" in PDFs as a text file. In Acrobat XI's Comment/Comments List I get a list of

  • Why, oh why is setting up a WDS such a pain now?!?

    I had a WDS of two AEBSs and an AExpress. I just added the new AEBS(n) to the flock, as the main base station, and I just can't seem to get them all talking. The AExpress seems to be the only one that likes it. For each base, I gave them all identica

  • How do we clone a database from RAC/ASM to RAC/ASM?

    Is there a best practice or recommended recipe for cloning from a RAC/ASM instance to another RAC/ASM instance? We've done single instance cloning in the past with RMAN and it looks like grid control does something similar -- until we try to clone fr