css - make text area like notepad JavaFX -
how can style text field notepad using css or code?
i tried said here, was:
textarea { background: url(http://i.stack.imgur.com/ynxjd.png) repeat-y; width: 600px; height: 300px; font: normal 14px verdana; line-height: 25px; padding: 2px 10px; border: solid 1px #ddd; }
but didn`t affect text area.
here i`m looking for:
thanks
approach
create lined linear gradient background content portion of textarea.
-jewelsea-lined-notepad: linear-gradient( 0px 0px 0px 11px, repeat, gainsboro, gainsboro 6.25%, cornsilk 6.25%, cornsilk );
implementation notes
the tricky part having lines in linear gradient line lines of text. thought simple specifying gradient size 1em (e.g. 1 measure of font size per line), didn't allow gradients align. specified gradient in absolute pixel sizes (found trial , error). unfortunately, approach, change fonts or font sizes text area, need adjust values in gradient manually. other sizing difficulty, seems work well.
references
- javafx css reference guide.
- modena.css - default javafx css stylesheet.
sample output
sample solution
notepad.java
import javafx.application.application; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.control.textarea; import javafx.scene.layout.priority; import javafx.scene.layout.vbox; import javafx.stage.stage; public class notepad extends application { @override public void start(stage stage) { textarea textarea = new textarea(); label title = new label( "benjamin franklin: selected quotes" ); title.getstyleclass().add("title"); vbox layout = new vbox( 10, title, textarea ); layout.setpadding(new insets(10)); vbox.setvgrow(textarea, priority.always); scene scene = new scene(layout); scene.getstylesheets().add(getclass().getresource( "notepad.css" ).toexternalform()); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } }
notepad.css
.root { -jewelsea-lined-notepad: linear-gradient( 0px 0px 0px 11px, repeat, gainsboro, gainsboro 6.25%, cornsilk 6.25%, cornsilk ); } .title { -fx-font-size: 16px; } .text-area { -fx-font-family: "comic sans ms"; -fx-font-size: 15px; } .text-area .content { -fx-background-color: -jewelsea-lined-notepad; } .text-area:focused .content { -fx-background-color: -fx-control-inner-background, -fx-faint-focus-color, -jewelsea-lined-notepad; }
Comments
Post a Comment