Comments (1)
I solved it.
Just selectRange(0, 0).
public class Find extends Application {
private final static List<SelectionImpl<Collection<String>, String, Collection<String>>> SELECTIONS = new ArrayList<>();
private CodeArea area = new CodeArea();
private TextField findInput = new TextField();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
area.replaceText(0, 0, "Your code goes here. \n Your code goes here.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nn\n\n\n\n\n\n\n\n\n\n\n\n");
findInput.setBackground(new Background(new javafx.scene.layout.BackgroundFill(Color.LIGHTGRAY, null, null)));
area.setBackground(new Background(new javafx.scene.layout.BackgroundFill(Color.WHITE, null, null)));
findInput.setPromptText("Find");
VBox vBox = new VBox(findInput, area);
primaryStage.setTitle("Find");
primaryStage.setScene(new Scene(vBox, 400, 400));
primaryStage.show();
findInput.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
for (SelectionImpl<Collection<String>, String, Collection<String>> selection : SELECTIONS) {
selection.selectRange(0, 0);
area.removeSelection(selection);
}
SELECTIONS.clear();
Pattern keyPattern = Pattern.compile(t1, Pattern.MULTILINE);
Matcher matcher = keyPattern.matcher(area.getText());
while (matcher.find()) {
addExtraSelection(matcher.start(), matcher.end());
}
}
});
}
private void addExtraSelection(int start, int end) {
SelectionImpl<Collection<String>, String, Collection<String>> extraSelection = new SelectionImpl<>(String.valueOf(start), area,
path -> {
// make rendered selection path look like a yellow highlighter
path.setStrokeWidth(0);
path.setFill(Color.YELLOW);
}
);
if (!area.addSelection(extraSelection)) {
throw new IllegalStateException("selection was not added to area");
}
// select something so it is visible
extraSelection.selectRange(start, end);
SELECTIONS.add(extraSelection);
}
}
from richtextfx.
Related Issues (20)
- How to set the size of tab in CodeArea? HOT 2
- StyleClassedTextArea + PageUp/PageDown -> NoSuchElementException + IndexOutOfBoundsException HOT 3
- Question: xml highlighter gives StackOverflowError HOT 2
- Question: How to move selected code right/left using Tab/Shift+Tab? HOT 3
- Question: How to show vertical lines in CodeArea for indentations? HOT 6
- Question: How to set selection color via code or CSS? HOT 4
- Question: how I can use InlineCssTextField with multiple color and pattern text please HOT 3
- CodeArea seems to intercept the input method, preventing it from being passed to other TextFields.
- Remove null character at end of pasted string
- JDK8 project HOT 1
- Question: is it possible to disable scrolling to bottom on appending text? HOT 2
- Question: How to set background color for current line/paragraph using CSS? HOT 4
- Question: Is possible to detect when INSERT mode is used? HOT 16
- Question: How to make wave underline? HOT 4
- Question: What is the strategy to implement Highlight All for found matches for modifiable text? HOT 5
- Question: Getting font size of the CodeArea HOT 3
- Question: when to use StyleSpans? HOT 8
- Bug: Observer is not removed from richChanges() HOT 3
- Question: how to get real size of one span at position X? HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from richtextfx.