-
Enhancement
-
Resolution: Unresolved
-
P4
-
8u40
-
Windows 7
My application makes use of the Two Level Focus behavior as it is controlled by remote (no keys for navigating between controls). However, sometimes there are areas in the application that only have a single focusable control, like a ListView. It is annoying to have to select the control first before it will respond to the other navigation keys.
Currently I use this hack to work around the problem:
{noformat}
tableView.requestFocus();
TwoLevelFocus.setInternalFocus(tableView);
{noformat}
Together with this support class:
{noformat}
package hs.mediasystem.util.javafx;
import java.lang.reflect.Field;
import javafx.scene.control.Control;
import com.sun.javafx.scene.control.behavior.BehaviorBase;
import com.sun.javafx.scene.control.behavior.ListViewBehavior;
import com.sun.javafx.scene.control.behavior.TableViewBehavior;
import com.sun.javafx.scene.control.behavior.TwoLevelFocusBehavior;
import com.sun.javafx.scene.control.skin.BehaviorSkinBase;
public class TwoLevelFocus {
public static void setInternalFocus(Control control) {
BehaviorBase<?> behavior = ((BehaviorSkinBase<?,?>)control.getSkin()).getBehavior();
if(behavior instanceof ListViewBehavior || behavior instanceof TableViewBehavior) {
try {
Field field = behavior.getClass().getDeclaredField("tlFocus");
field.setAccessible(true);
TwoLevelFocusBehavior twoLevelFocusBehavior = (TwoLevelFocusBehavior)field.get(behavior);
if(twoLevelFocusBehavior != null) {
twoLevelFocusBehavior.setExternalFocus(false);
}
}
catch(Exception e) {
throw new IllegalStateException(e);
}
}
}
}
{noformat}
Currently I use this hack to work around the problem:
{noformat}
tableView.requestFocus();
TwoLevelFocus.setInternalFocus(tableView);
{noformat}
Together with this support class:
{noformat}
package hs.mediasystem.util.javafx;
import java.lang.reflect.Field;
import javafx.scene.control.Control;
import com.sun.javafx.scene.control.behavior.BehaviorBase;
import com.sun.javafx.scene.control.behavior.ListViewBehavior;
import com.sun.javafx.scene.control.behavior.TableViewBehavior;
import com.sun.javafx.scene.control.behavior.TwoLevelFocusBehavior;
import com.sun.javafx.scene.control.skin.BehaviorSkinBase;
public class TwoLevelFocus {
public static void setInternalFocus(Control control) {
BehaviorBase<?> behavior = ((BehaviorSkinBase<?,?>)control.getSkin()).getBehavior();
if(behavior instanceof ListViewBehavior || behavior instanceof TableViewBehavior) {
try {
Field field = behavior.getClass().getDeclaredField("tlFocus");
field.setAccessible(true);
TwoLevelFocusBehavior twoLevelFocusBehavior = (TwoLevelFocusBehavior)field.get(behavior);
if(twoLevelFocusBehavior != null) {
twoLevelFocusBehavior.setExternalFocus(false);
}
}
catch(Exception e) {
throw new IllegalStateException(e);
}
}
}
}
{noformat}