Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issues in making label selectable when used with text area

914591Mar 12 2012 — edited Mar 12 2012
I have used the following code (which was given in the thread : 10022729 ]

which shows how to make label selectable with text field. )
public class TrialArea extends Application {
>>public void start(final Stage stage) throws Exception {
>>StackPane layout = new StackPane();
>>layout.setStyle("-fx-background-color: cornsilk; -fx-padding:10; -fx-font-size: 20");
>>
>>Label label1 = (new Label("jqhrjhhhhhhdsfdsfdsfdfdsdsfsdfdsdsdsfsddsdsdfsdfsddsfsfsddsfdsdedsfssdfhhhhhhhhhhhhhhhhhhhhkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\njqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\njqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\njqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\n jqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\n jqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\n jqhrkjhejwqrhjwhj ewjrhewjkrjew ewjhrjewjwke \n qwjkhrjkwerehw \n jkehrkjewhrjkew\n "));
>>
>>label1.setWrapText(true);
>> label1.setPrefWidth(480);
>>label1.setMaxWidth(480);
>>layout.getChildren().add(
makeSelectable(label1)
);
>> Scene scene = new Scene(layout);
>>stage.setScene(scene);
stage.show();
}

/** @return the passed in label made selectable. */
private Label makeSelectable(Label label) {
StackPane textStack = new StackPane();
TextArea textField = new TextArea(label.getText());
>>
>> textField.setEditable(false);
textField.setWrapText(true);
textField.setStyle(
" -fx-background-color: transparent; -fx-background-insets: 0; -fx-background-radius: 0;"
);
>>
>>
// the invisible label is a hack to get the textField to size like a label.
Label invisibleLabel = new Label();
invisibleLabel.textProperty().bind(label.textProperty());
invisibleLabel.setVisible(false);


>> textStack.getChildren().addAll(invisibleLabel, textField);
label.textProperty().bindBidirectional(textField.textProperty());
label.setGraphic(textStack);

label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
return label;


}

public static void main(String[] args) {
>> Application.launch(args);
>> }
}
The issue I am facing is that with text area, the scroll bar is visible, which does not go with label. The label is being selected properly, but how to remove the scroll bar?

Edited by: Amrita Dasgupta on Mar 11, 2012 11:38 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2012
Added on Mar 12 2012
0 comments
221 views