2

I want to start editing the TextArea after ending of tittle label as below image. and also display linings. Display text is label not a text of textarea.

enter image description here

Thanks in advance...

CTN
  • 335
  • 1
  • 18
  • 1
    The title text should be either a Label placed above the TextArea, or [promptText](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextInputControl.html#promptTextProperty--). As for the lines, I doubt it’s possible. – VGR Nov 17 '16 at 18:01
  • 2
    The line portion of the question is answered in: [make text area like notepad JavaFX](http://stackoverflow.com/questions/29636578/make-text-area-like-notepad-javafx). It's always best to ask a single question per question (e.g. one question for how to handle the title string and a different question for how to display lines in the text area). – jewelsea Nov 17 '16 at 18:33
  • @VGR It is an Label. – CTN Nov 18 '16 at 03:17
  • @jewelsea It's working for lines. but what should i do for padding in first line. Thanks.. – CTN Nov 18 '16 at 03:37
  • Is It possible using "-fx-shape"? – CTN Nov 18 '16 at 06:52

1 Answers1

2

You may have a specialized implementation of TextArea which will prevent the editing the padded text.

Example:

public class FirstLinePaddedTextAread extends javafx.scene.control.TextArea {
    private int offset;

    public FirstLinePaddedTextAread(String padded) {
        this.offset = padded.length();
        this.setText(padded);
        this.positionCaret(offset);

        this.setOnKeyPressed(event -> consumeIfCaretIsOnReadOnlyArea(event));
        this.setOnKeyTyped(event -> consumeIfCaretIsOnReadOnlyArea(event));
        this.setOnKeyReleased(event -> consumeIfCaretIsOnReadOnlyArea(event));
    }

    private void consumeIfCaretIsOnReadOnlyArea(javafx.scene.input.KeyEvent event) {
        if (getCaretPosition() < offset) {
            if (!event.getCode().isNavigationKey())
                event.consume();

        } else if (getCaretPosition() == offset) {
            if (event.getCode() == javafx.scene.input.KeyCode.DELETE
                    || event.getCode() == javafx.scene.input.KeyCode.BACK_SPACE) {
                event.consume();
            }
        }
    }
}
skadya
  • 4,330
  • 19
  • 27
  • Thanks skadya It's working for me..I have an another issue to disable scrollbars of text area. – CTN Nov 28 '16 at 03:52