12 Replies Latest reply: May 26, 2012 1:16 PM by 937018 RSS

    get and set the scroll bar position of tableView

    937018
      hi
      a want to set and get the scroll bar position of the tableview
        • 1. Re: get and set the scroll bar position of tableView
          jsmith
          Is this tableView.scrollTo(index) method sufficient for you?
          http://docs.oracle.com/javafx/2/api/javafx/scene/control/TableView.html#scrollTo%28int%29

          If you need direct references to the scrollbar's for the TableView, this is also possible:
          for (Node n: table.lookupAll(".scroll-bar")) {
            if (n instanceof ScrollBar) {
              ScrollBar bar = (ScrollBar) n;
              System.out.println(bar.getOrientation() + ": range " + bar.getMin() + " => " + bar.getMax() + ", value " + bar.getValue());
            }
          }
          executed after the tableview has been rendered in a displayed scene (i.e. after stage.show()).
          • 2. Re: get and set the scroll bar position of tableView
            937018
            thank you thank you thank you thank you
            Another question. setOnscroll function does not function
            • 3. Re: get and set the scroll bar position of tableView
              jsmith
              setOnscroll function does not function
              You may want to create a new thread with short complete example code (mention in the new thread what you expect your setOnScroll call to achieve).
              • 4. Re: get and set the scroll bar position of tableView
                jsmith
                Are you sure you want to use setOnScroll to listen to scroll events rather than set the value of the scroll bar position via the tableView.scrollTo api (which I would recommend) or the scrollBar.setValue() api?
                for (Node n: table.lookupAll(".scroll-bar")) {
                  if (n instanceof ScrollBar) {
                    ScrollBar bar = (ScrollBar) n;
                    System.out.println(bar.getOrientation() + ": range " + bar.getMin() + " => " + bar.getMax() + ", value " + bar.getValue());
                      if (bar.getOrientation().equals(Orientation.VERTICAL)) {
                      bar.setValue(0.5);
                    }
                  }
                }
                If you did really, really want to use setOnScroll, then you could do something like this:
                Node flow = table.lookup("VirtualFlow");
                if (flow != null) {
                  final EventHandler<? super ScrollEvent> originalScrollHandler = flow.getOnScroll();
                  flow.setOnScroll(new EventHandler<ScrollEvent>() {
                    @Override public void handle(ScrollEvent event) {
                      System.out.println(event);
                      originalScrollHandler.handle(event);
                    }
                  });
                }  
                Though you would be better off just using an eventfilter rather than using the strange lookup and setOnScroll chaining method in the above code.
                table.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
                  @Override public void handle(ScrollEvent event) {
                    System.out.println(event);
                    // uncomment if you don't want the default table scroll events processing to take effect.
                    //event.consume(); 
                  }
                });
                • 5. Re: get and set the scroll bar position of tableView
                  937018
                  thanc jsmith

                  Is it possible to edit the column header of tableview
                  • 6. Re: get and set the scroll bar position of tableView
                    jsmith
                    Is it possible to edit the column header of tableview
                    Yes.

                    Perhaps you want to do something like the code here, which sets a graphic for the table header label which comprises of an edit box, you can switch the label back to plain text display once the edit is committed.
                    http://stackoverflow.com/questions/10525311/can-i-place-textfield-on-tableview-header-column-on-javafx-2
                    • 7. Re: get and set the scroll bar position of tableView
                      937018
                      Thank you very much jsmith. you is a very nice man.
                      another question if you allow
                      there is a method to create a fixed line in the bottom of the table to Display the totalite values
                      • 8. Re: get and set the scroll bar position of tableView
                        jsmith
                        another question if you allow there is a method to create a fixed line in the bottom of the table to Display the totalite values
                        Nope, no such method.
                        You will need to calculate the totals in your own code.
                        Then use a seperate table or grid or some other layout placed under the main table to get the totals to display.
                        Best to ask new questions on seperate threads so that the info does not get all jumbled up.
                        • 9. view the graphical component of right to left
                          937018
                          there exist a method to display the graphical component of right to left as in method setComponentOrientation ?.
                          • 10. Re: view the graphical component of right to left
                            jsmith
                            I don't quite understand the question and if it is not to do with the original question of "get and set the scroll bar position of tableView" then the new question should be in it's own thread.

                            Perhaps you are asking about the orientation property which can be set on some controls:
                            http://java-buddy.blogspot.com/2012/02/set-javafx-listview-orientation-in.html
                            http://docs.oracle.com/cd/E17411_01/javafx/2.0/api/javafx/geometry/Orientation.html
                            http://docs.oracle.com/cd/E17411_01/javafx/2.0/api/javafx/scene/control/ListView.html#setOrientation%28javafx.geometry.Orientation%29
                            • 11. Re: view the graphical component of right to left
                              Richard Bair
                              Or he might be asking about right-to-left language support (swing used "Component Orientation" as the name for this). In which case, it is targeted at 3.0.
                              • 12. Re: view the graphical component of right to left
                                937018
                                Yes This is what I want to say.