javafx - Setting background color of each character in textArea -
i'am new javafx. want in following image inside textarea. think can done using label , set background color of it. how?
it can done putting label
layout container, hbox
:
private final random random = new random(); private final color[] colors = { color.red, color.green, color.blue, color.yellow }; @override public void start( final stage primarystage ) { hbox hbox = new hbox(); string str = "my-string-val"; ( string s : str.split( "" ) ) { label l = new label( s ); l.setborder( new border( new borderstroke( color.black, borderstrokestyle.solid, cornerradii.empty, borderwidths.default ) ) ); l.setbackground( new background( new backgroundfill( colors[random.nextint( colors.length )], cornerradii.empty, insets.empty ) ) ); l.setprefwidth( 20 ); l.setalignment( pos.center ); l.setfont( font( "arial", fontweight.bold, 16 ) ); hbox.getchildren().add( l ); } final scene scene = new scene( hbox, 800, 600 ); primarystage.setscene( scene ); primarystage.show(); }
Comments
Post a Comment