Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX TextArea Hiding Scroll Bars

Tags:

javafx-2

I have a TextArea() and would like to hide the vertical/horizontal scroll bars. I see that the control seems to have a built in scroll-pane that shows as needed.

    TextArea numberPane = new TextArea();

    numberPane.setEditable(false);
    numberPane.setMaxWidth( 75 );

    // Set the characteristics of our line number pane
    numberPane.setId( "line-number-pane" );

In my CSS file I have the follow settings.

    #line-number-pane
    {
        -fx-text-fill: white;
        -fx-background-color: black;
        -fx-font: 12px "Courier New";
        -fx-font-family: "Courier New";
        -fx-font-weight: bold;
    }

    #line-number-pane .scroll-pane
    {
        -fx-hbar-policy : never;
        -fx-vbar-policy : never;
    }

As expected the text area font/color/size works just fine. However, the scroll-pane policy doesn't seem to work.

Should I be able to hide the scroll bars via the CSS file or is there some code that will do the trick.

Thanks.

like image 947
Omey Nandyal Avatar asked Jan 08 '13 00:01

Omey Nandyal


2 Answers

From How can I hide the scroll bar in TextArea?:

Remove Horizontal Scrollbar

textArea.setWrapText(true);

Remove Vertical Scrollbar

ScrollBar scrollBarv = (ScrollBar)ta.lookup(".scroll-bar:vertical");
scrollBarv.setDisable(true);

CSS

.text-area .scroll-bar:vertical:disabled {
    -fx-opacity: 0;
}
like image 84
Travis Avatar answered Nov 06 '22 02:11

Travis


I just did it very simply using a StyleSheet:

CSS

.text-area .scroll-bar:vertical {
    -fx-pref-width: 1;
    -fx-opacity: 0;
}
.text-area .scroll-bar:horizontal {
    -fx-pref-height: 1;
    -fx-opacity: 0;
}

No need for all that whacky code.

like image 1
Michael Sims Avatar answered Nov 06 '22 03:11

Michael Sims