下面列出了怎么用javafx.scene.AccessibleRole的API类实例代码及写法,或者点击链接到github查看源代码。
private void initialize() {
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.TOGGLE_BUTTON);
// alignment is styleable through css. Calling setAlignment
// makes it look to css like the user set the value and css will not
// override. Initializing alignment by calling set on the
// CssMetaData ensures that css will be able to override the value.
((StyleableProperty<Pos>) (WritableValue<Pos>) alignmentProperty()).applyStyle(null, Pos.CENTER);
this.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
doSelected();
}
});
}
private void initialize() {
getStyleClass().add(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.DATE_PICKER);
setEditable(true);
}
public StyledTextField(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, String, S> document)
{
super( initialParagraphStyle, applyParagraphStyle, initialTextStyle, applyStyle, document, true );
getStylesheets().add( STYLE_SHEET );
getStyleClass().setAll( "styled-text-field" );
setAccessibleRole( AccessibleRole.TEXT_FIELD );
setPrefSize( 135, HEIGHT );
addEventFilter( KeyEvent.KEY_PRESSED, KE -> {
if ( KE.getCode() == KeyCode.ENTER ) {
fireEvent( new ActionEvent( this, null ) );
KE.consume();
}
else if ( KE.getCode() == KeyCode.TAB ) {
traverse( this.getParent(), this, KE.isShiftDown() ? -1 : +1 );
KE.consume();
}
});
addEventFilter( MouseEvent.MOUSE_PRESSED, ME -> selectAll = isFocused() );
focusedProperty().addListener( (ob,was,focused) -> {
if ( ! was && focused && selectAll ) {
selectRange( getLength(), 0 );
}
else if ( ! focused && was ) {
moveTo( 0 ); requestFollowCaret();
}
selectAll = true;
});
super.setWrapText( false );
wrapTextProperty().addListener( (ob,ov,wrap) -> {
if ( wrap ) { // veto any changes
wrapTextProperty().unbind();
super.setWrapText(false);
}
});
}