java - focus content node of pagination control -
I have a ListView that is in the form of a content node in the Java Fx pagination control. My goal is to set focus on ListView after selecting a new page. Problems with My Viewpoint Sometimes the focus on ListView is but sometimes not.
How can I ensure that the focus will be on the list page, after selecting a new page?
Platform: Windows 7 JDK 1.8.0.25 (64-bit)
Code:
package test.focus; Import javafx.application.Application; Import static javafx.application.Application.launch; Import javafx.collections.FXCollections; Import javafx.collections.ObservableList; Import javafx.scene.Node; Import javafx.scene.Scene; Import javafx.scene.control.ListView; Import javafx.scene.control.Pagination; Import javafx.scene.layout.BorderPane; Import javafx.stage.Stage; Import javafx.util.clallback; Application increases in the public class main app {@ Override Public Womens Start (Stage Stage) throws an exception {paging pinignation = New Zealand (5); Last Supervisory List & lt; String & gt; Texts = FXCollections.observableArrayList ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"); Last list view & lt; String & gt; TextsListView = New ListView & lt; & Gt; (); Paging .setupface (new callback & lt; integer, node & gt; () {@ override public node call (integer page) {textsListView.setItems (FXCollections.observableArrayList (texts.subList (pages, pages + 2)); textsListView .getSelectionModel () .select (0); // Platform.RunLater does not work, LISTView.requestFocus (); return texts LISTView;}}); BorderPan Root = New BorderPan (Pagination); Visual View = New View (Route, 800, 600); Stage.setTitle ("Focus Release"); Stage.setScene (view); stage show(); } Public static zero main (string [] args) {launch (args); }}
You always need two things to list in the list:
-
Endorsement
Focus should not be part of the traversal cycle. - Every time the list loses focus, it should be requested again.
This works for me:
last list view & lt; String & gt; TextsListView = New ListView & lt; & Gt; (); TextsListView.focusedProperty () AddListener ((ov, b, b1) - & gt; {if (! B1) {textsListView.requestFocus ();}}); Pagination.setFocusTraversable (false); Pagination.setPageFactory (page -> {textsListView.setItems (FXCollections.observableArrayList (texts.subList (pages, pages + 2)) textsListView.getSelectionModel (.) Select (0); textsListView.requestFocus (); Return Text LISTView;});
edit
To avoid inventory requests for focus every time it loses it, Then this method will request focus for it only when the new page loads only:
the last list view & lt; string & gt; TextsListView = new ListView & lt; & gt; () ; Last Booleanproperty Voded = new simple boolean property (wrong); pagination.setFocusTraversable (false); endorsement page - & gt; {textsListView.setItems (FXCollections.observableArrayList (texts.subList (pages, pages + 2)); textsListView.getSelectionModel (.) Select (0); Loaded .set (true); return text LISTView;}); Loaded.addListener ((ov, b, b1) -> {if (b1) {textsListView.requestFocus ( ); Loaded; set (false);}}};
Comments
Post a Comment