Find the element of list, table cell, node of the tree, or control by location

One of my favorite on the swing features has the opportunity to get a reference to the component UI via Container.getComponentAt (int x, int y), or a particular list item through JList.locationToIndex (Point p) (or other similar methods). I was not able to find the same or similar functionality in JFX so far... anyone can point me in the right direction?

Thank you!

I don't know a way. When I started with JavaFX I had the same issue; However, I found that I actually need to do. Swing I ever need it when I was, say, treatment the mouse clicks on a JList. In JavaFX, you can register handlers with the cells directly. This does not work in the swing (in the least, not without a huge amount of effort). As well as in the swing, how to map a mouse click to a JList to the list item corresponding was to register a listener with the JList and then move the mouse click coordinates to locationToIndex (...), in JavaFX you just save the listener with the cell:

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;

public class ListTest extends Application {

  @Override
  public void start(Stage primaryStage) throws Exception {
    BorderPane root = new BorderPane();
    ListView listView = new ListView();
    listView.getItems().addAll("Apples", "Oranges", "Grapefruit", "Bananas");
    listView.setCellFactory(new Callback, ListCell>() {
      @Override
      public ListCell call(ListView param) {
        return new CustomListCell();
      }
    });
    root.setCenter(listView);
    Scene scene = new Scene(root, 300, 300);
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  private class CustomListCell extends ListCell {
    private final EventHandler listener = new EventHandler() {
      @Override
      public void handle(MouseEvent event) {
        System.out.printf("Mouse clicked on list cell with %s (item number %d)",getItem(), getIndex());
        if (isEmpty()) {
          System.out.print(" (Empty cell)");
        }
        System.out.println();
      }
    };
    private CustomListCell() {
      this.addEventHandler(MouseEvent.MOUSE_CLICKED, listener);
    }
    @Override
    public void updateItem(String item , boolean empty) {
      super.updateItem(item, empty);
      if (! empty) {
        setText(item);
      } else {
        setText(null);
      }
    }
  }

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

}

Of course, maybe it's not your use case, and you really need this feature. Someone else can have a more direct response...

Tags: Java

Similar Questions

  • drivers LabVIEW for agilent e4432b, cannot find the way to control multitone?

    drivers LabVIEW for agilent e4432b, cannot find the way to control multitone? How to deal

    Hello Brownheart,

    Drivers for the instruments aren't supposed to cover all applications use of instruments, only for the most common uses. No matter if multitone is a common use for this instrument, a brief review of the functions available in the driver does not have this feature.

    What you have to do is to create your own config VI using the information of the use of the programming unit. Is not ideal, but at least the driver NOR provided gives you a starting point for adding this feature.

  • I do not understand this step "we can assume any MAC address we want by finding the key that controls the NIC we want to change.

    Hello
    anyone ever did in Winxp with success. I do not understand this step

    «We can assume that any MAC address, we want by finding the key that controls the NIC we want change, put in a value chain called "NetworkAddress" and affecting the MAC address we want to use formatted as a hexadecimal 12-digit number (example: 000000000001).»

    It is a part of the "Windows 2000/XP/Vista: The Hard Way.

    from this link
    http://www.irongeek.com/i.php?page=security/changemac

    Concerning

    original title: change MAC address

    Hello

    I suggest to refer to this thread and follow the steps in this thread and check if that helps:

    http://social.technet.Microsoft.com/forums/en/w7itpronetworking/thread/697bf48c-A226-4315-8875-2bbeddf16db2

    The steps in this link are for Windows 7 and they are valid for Windows XP.

    It will be useful.

  • Where can I find the new tab controls, not wheel

    I can't change the new tab to display the tiles.

    You can watch the pref browser.newtab.url the topic: config page and set this pref to the URL of your preferred the new tab page.
    You can use these special pages or set the pref to the URL of your preferred the new tab page.

    • the new default tab with the tiles page is on: newtab
    • the default homepage is Subject: Home
    • to a blank page, you can use Subject: vacuum

    The pref browser.newtabpage.enabled must be set to true to use the page defined through browser.newtab.url like the new tab page.

    You can open the topic: config page via the address bar.
    You can accept the warning and click on "I'll be careful" to continue.

    If you do not keep the changes after a reboot or have problems with preferences, see:

  • hyperlink in the table cell?

    Hi all

    We need to navigate a path for each row in the table control. Is it possible to have a hyperlink in a table for each row cell? or do I have to use button battery to do the same thing?

    Kind regards

    Kanu

    The answer is, you can't. However, the custom hyperlink control is open-source. You can find the source in toolslib\custctrl\hyperlinkctrl.c. It's a pretty simple code module, so it is not all that difficult to modify this code so that it could work in a table cell, rather than a message text control.

    Luis

  • Find the RMAN backup SNA

    Hello

    I have a complete backup of my 10g (10.2.0.5) database backup that was taken in the State of editing. The backup includes not the controlfile inside because the statement of recovery we use for recovery of the standby database is restore database using backup controlfile until cancel and type backup controlfile. Now I need to find the RCS included in the backup that I plan to take a SNA based incremental backup of the Production and apply.

    How to find information this backup SNA in my scenario?

    Kind regards

    007

    Once you take the incremental on the primary backup, while it is being restored on the eve, why not run a BACKUP of the LIST on the primary?  That would show the datafile SNA control point located in the backup that you send to the wait.

    Hemant K Collette

  • find the needle in the css (part 2)

    can someone please take a look at the links below and tell me where I might find the code that controls:

    (a) the copy on the right which starts by "JOHN MCCAIN WAS BORN ON 29 August 1936...".
    (b) the headings in the sidebar (on..., Pages, categories, etc. - but not the one called 'Mailing List')

    http://www.thingsyoungerthanmccain.com/
    YLE.CSS http://www.thingsyoungerthanmccain.com/wp-content/themes/minima-Black-for-WordPress-115/St


    Thank you!

    > can someone please take a look at the links below and tell me where I
    > would be
    > find the code that controls:

    The styles are scattered through the CSS and who inherits. For example, the
    in the sidebar headers are using styles declared in CSS for h2, #menu
    UL and maybe a few others.

    Because they have their own classes, however, you can easily get around that
    yourself if you wish.

    -Darrel

  • With 29.0.1 I can't find the reload or stop icons. No, they do not have

    With the right version updated with what precedes. Where can I find the 'reload' and icons 'stop' located in the top right of my toolbar. Appreciate any help with this issue.

    Why? Why? Why? Why remove the useful stuff?

  • Cannot find the downloaded files.

    So, I just got a videofile of a friend in the chat, but I can't find anywhere on my PC. I can simply open the video and watch it. I can not find the folder where it is located, to move, rename, or delete.

    What gives? Why should you even to change anything on the downloads?

    Too bad. Finally found. Skype C:\Users\Username\AppData\Roaming\Skype\My received files
    Why would you do that well?

  • Director of Windows can not find the file

    I made a presentation / film in windows movie maker, and it worked fine.  Then when I went to access the movie a month later, all photos in the film are absent, and the Director of windows message can not find the file you want to locate the file... There are a lot of pictures, I don't want to go to each of them... What's happening on why it does not find the photo files now?

    I made a presentation / film in windows movie maker, and it worked fine.  Then when I went to access the movie a month later, all photos in the film are absent, and the Director of windows message can not find the file you want to locate the file... There are a lot of pictures, I don't want to go to each of them... What's happening on why it does not find the photo files now?

    =============================
    The source files have been moved or deleted?
    The only records of the files project makes it the path...
    check the source file.

    If you navigate to the folder, they are saved in...
    the path must be restored. You should not
    to go to each photo. John Inzer - MS - MVP - Digital Media Experience - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • find the needle in the css (redux)

    can someone more adept at css/firebug take a look at the following link and let me know where I could find the styles that control the title of the message (in this case, the scale of the ACE)?

    http://www.joequint.com/blog/?p=257

    Thank you!

    style.CSS ~ .entry-title

    #content .entry-title {padding: 0 8px; margin: 0 0 22px;font-size:48px;line-height:44px;letter-spacing:-1px;font-weight:200;float:none;clear: ;}}

    #content .entry-title {police-weight: 200}

    PS. I use FF Web Developer Toolbar

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    http://ALT-Web.com/
    http://Twitter.com/ALTWEB

  • Change the listener not notified when the tree item is deselected

    I attach a listener to the selected index of the view tree selection model property to detect when a user selects or deselects on or other nodes in a tree, but it seems that the listener is not notified when the user deselects a node. So, if a user selects both nodes, and then while holding the CTRL + key deselects one of selected nodes the tree view control deselects the node, but the change listener is not notified. This is a bug or I do something wrong?

    I use the GA of JavaFX 2.1 on Windows 7 version.

    Thank you.
    Stefan

    Import javafx.application.Application;
    Import javafx.beans.value.ChangeListener;
    Import javafx.beans.value.ObservableValue;
    Import javafx.scene.Node;
    Import javafx.scene.Scene;
    Import javafx.scene.control.SelectionMode;
    Import javafx.scene.control.TreeItem;
    Import javafx.scene.control.TreeView;
    Import javafx.scene.image.Image;
    Import javafx.scene.image.ImageView;
    Import javafx.scene.layout.StackPane;
    Import javafx.stage.Stage;

    SerializableAttribute public class TreeViewSample extends Application {}

    rootIcon private final node = new ImageView)
    New Image (getClass () .getResourceAsStream ("Folder.gif"))
    );

    Public Shared Sub main (String [] args) {}
    Launch (args);
    }

    @Override
    public void start (point primaryStage)
    {
    primaryStage.setTitle ("Tree View sample");

    TreeItem < String > rootItem = new TreeItem < String > ("Inbox", rootIcon);
    rootItem.setExpanded (true);

    for (int i = 1; i < 6; i ++)
    {
    TreeItem < String > element = new TreeItem < String > ('Message' + i);
    rootItem.getChildren () .add (item);
    }

    TreeView < String > tree = new TreeView < String > (rootItem);
    tree.getSelectionModel () .setSelectionMode (SelectionMode.MULTIPLE);
    tree.getSelectionModel () .selectedIndexProperty () .addListener (new ChangeListener < number >)
    {
    @Override
    public void changed (ObservableValue <? extends number > ov, number oldIndex, number newIndex)
    {
    System.out.println ("selection changed.");
    }
    });

    Root StackPane = new StackPane();
    root.getChildren () .add (tree);
    primaryStage.setScene (new scene (root, 300, 250));
    primaryStage.show ();
    }
    }

    The value of the selected index does not change in these cases, because it reflects the last selected index (useful for single selection). It is not weird is possible to get a selected index which is not actually enabled (you can report a bug for this I think).

    However, if you want to keep track of the complete selection, try adding a ListChangeListener to the selectedIndices of the selection model. This one is triggered a change every time.

  • Change the background color of a table cell, depending on the selection in a drop-down list

    I have a drop-down list wrapped in a subform in a table cell. Users can choose green, yellow or red, and I want the background color to change according to their choice.

    Can you tell me why this script does not work? I'm sure that some of you, dear friends can see in a second.


    If (this. ListItem == "green") {}

    Subform1.DropDownList1.fillColor = "000,128,000"; BackgroundFill = "solid";

    }

    If (this. ListItem == 'yellow') {}

    Subform1.DropDownList1.fillColor = "255,128,000";

    }

    If (this. ListItem == 'red') {}

    Subform1.DropDownList1.fillColor = "255,000,000;

    }


    Thank you

    Hello

    I think you should be able to use the following code in the event change of the dropdownlist control.

    Form1. #subform [0]. Table1.row2.DropDownList1::change - (JavaScript, client)

    If {(xfa.event.change=="green)"}

    this.fillColor = "000,128,000";

    }

    If {(xfa.event.change=="yellow)"}

    this.fillColor = "255,128,000";

    }

    If {(xfa.event.change=="red)"}

    this.fillColor = "255,000,000;

    }

    Concerning

    Bruce

  • How to drive the content of a text field or table from a drop-down list selection cell?

    Users will choose an option in a menu drop-down. I want their selection to control the contents of the cells in a table or text elsewhere on the form fields.

    For example, 'The coldest season of the year' by selecting 'winter' in the menu drop-down displays in a table cell.

    Thanks in advance for the help.

    Nick

    Hi Nick,

    Here are some examples:

    https://Acrobat.com/#d=pxtis4z3OxCqWxajZwDS2Q

    https://Acrobat.com/#d=20lQl9JfL19aBtbPC1WYbw

    https://Acrobat.com/#d=Hi0ZwVgVB1PWbxc6OJ0z4A

    If you open these in LC Designer, you can view the script by selecting the menu drop down and looking at the script at the top of the window Editor. If the script editor is a single line, you can drag the lower edge to make it bigger.

    Good luck

    Niall

  • How to find the third element table pl/sql ina

    Hello friends,

    I have a pl/sql table of NUMERIC type, where am store all salaries of employees.

    I want to find the third bigger payday by browsing through the pl/sql table.

    Pls advice.

    Thank you/kumar
    DECLARE
        TYPE max_earnings_type IS TABLE OF NUMBER;
        TYPE max_earnings_sorted_type IS TABLE OF NUMBER
          INDEX BY BINARY_INTEGER;
        max_earnings_tab        max_earnings_type;
        max_earnings_tab_sorted max_earnings_sorted_type;
        m number;
    BEGIN
        SELECT  sal + comm
          BULK COLLECT
          INTO  max_earnings_tab
          FROM  emp;
        FOR v_i in 1..max_earnings_tab.count LOOP
          IF max_earnings_tab(v_i) IS NOT NULL
            THEN
              max_earnings_tab_sorted(max_earnings_tab(v_i)) := 1;
          END IF;
        END LOOP;
        m := max_earnings_tab_sorted.last;
        DBMS_OUTPUT.PUT_LINE('MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
        m := max_earnings_tab_sorted.prior(m);
        DBMS_OUTPUT.PUT_LINE('Second MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
        m := max_earnings_tab_sorted.prior(m);
        DBMS_OUTPUT.PUT_LINE('Third MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
    END;
    /
    MAX value in PL/SQL table is 2650
    Second MAX value in PL/SQL table is 1900
    Third MAX value in PL/SQL table is 1750
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

Maybe you are looking for