I'm new to javafx and am trying to display large amount of text in textflow. It displays fine, but I just cannot figure out how to delete the text.
So what I'm trying to do is delete all Text nodes from textFlow like so
textFlow.getChildren().removeAll();
But when I do this and add something to textFlow, it shows after the text that was already displayed there. I would like the text that was there removed and show the added text from the beginning of the textflow.
I guess I have to somehow rerender the view of textflow, but I don't know how. So how do I delete everything and add Text anew?
removeAll(...) will remove all the values you pass as parameters: in your case there are none, so it doesn't remove anything. Use
textFlow.getChildren().clear();
Related
These are the following things i want to know:
I want to highlight different text in jtextarea by selecting them by mouse.
I also want to get all the highlighted text later.
I also want to know how to remove particular highlighted line.
What code can i use ?
You need to use a Highlighter:
Highlighter hl = textArea.getHighlighter();
Read the API for the methods that allow you add, remove and display the highlights.
I'm running into an issue with the requestFocus() method. Whenever I click on a link from a VBox table in my application, a details menu drops down indicating username etc which are editable. The problem is, when I open the link in the VBox using the spacebar, JavaFX puts a focus on the TextField, but highlights it. By the time I release the spacebar, the highlighted text is deleted.
Basically, when the TextField is given focus using a spacebar, the entire contents are highlighted and replaced with a space character. Pushing enter to open the link still highlights the text, but doesn't do anything else since it doesn't add any characters.
How do I make sure the text inside a TextField doesn't get highlighted?
Thanks.
The solution for TextField (entire content) doesn't get highlighted is adding the .selectedEnd() after the .requestFocus()
textField.requestFocus();
textField.selectEnd();
However, i'm not really sure for your case that deal with spacebar. Hope this help.
I have a table of forms which accepts first name, last name etc. When I navigate through using the tab key and enter some text in first name, all of the text disappears and that row gets selected. I have tried almost all techniques.
Is there any way we can avoid that using coding?
If I use the mouse then it wont give that error.
Assuming an otherwise correct use of JTable, you may need to terminate the edit when focus is lost, as suggested here and here:
table.putClientProperty("terminateEditOnFocusLost", true);
I have a Java SWT GUI with a multiline Text control. I want to append lines of text to the Text control without affecting the position of the cursor within the text box. In particular, the user should be able to scroll and select text at the top of the Text control while new text lines are appended to the bottom.
Is this possible?
I switched to using a StyleText control to fix flickering issues when adding text. With this control I found the following code fixed the issue of appending text without scrolling to the new location.
textOutput.setRedraw(false);
int scrollP = textOutput.getTopIndex();
Point selectionP = textOutput.getSelection();
textOutput.append(traceText);
textOutput.setSelection(selectionP);
textOutput.setTopIndex(scrollP);
textOutput.setRedraw(true);
I am displaying text in a Java JEditorPane using HTML to fomrat the text. I am also designing a search function that finds text in the JEditorPane selects the text and then scrolls to it. My problem is creating an algorithim that will actually specify the beginning and ending position for the selection.
If I simply retrieve the text using myeditorpane.getText(), then find the search string in the result, the wrong selection start and end positions are calculated with the wrong text being selected (the tags are throwing the calculation off). I tried removing the html tags by executing a replace all function text.().replaceAll("\<.*?>","") before searching for the text (this replace all removes all text in between the tags) but still the wrong selection points are calculated (although I'm getting close :-)).
Does anyone have an easy way to do this?
Thanks,
Elliott
You probably want to be working with the underlying Document, rather than the raw text, as suggested in this HighlightExample.
You need to find the start location of the text. I guess something like:
int offset = editorPane().getDocument().getText().indexof(...);
Then to scroll you can use:
editorPane.scrollRectToVisible( editorPane.viewToModel(offset) );
Read up on Text and New Lines for more info.