내 JTextPane에서 Find 메커니즘 (텍스트 편집기 또는 단어)을 구현하려고합니다. 다음/이전 옵션 (위/아래 화살표)을 사용하여 찾은 모든 단어를 강조하고 싶습니다. 이렇게 간단한 방법이 있습니까?JTextPane에서 텍스트 찾기 메커니즘을 구현하는 방법은 무엇입니까?
2
A
답변
2
나는 전문가가 아니다, 나는 다음과 같은 코드 작업을 발견 : -
public static void GetTextToFindAndFind(String textToFind, int ignorecase, int findCounter){
// findCounter = 0 or 1. 0 represents find and 1 represents findCounter.
String Current2 = textPane.getText();
if(findCounter ==0){
if(textToFind == null){
optionPane.showMessageDialog(null, "Please Enter Text.", "Error", 0);
}
else if(textToFind.isEmpty()){
optionPane.showMessageDialog(null, "Please Enter Text.", "Error", 0);
}
else{
// Use any Character. But I a suggest to use a character from an Encrypted file.
Replacer = "¥";
CurrentText = textPane.getText();
if(ignorecase==1){
CurrentText = CurrentText.toLowerCase();
textToFind = TextToFind.toLowerCase();
}
int counter = 0;
readtext = new StringReader(CurrentText);
readBuffer = new BufferedReader(readtext);
try {
String Line = readBuffer.readLine();
int found = 0;
while(Line!=null || found != 1){
if(Line.contains(TextToFind)){
Line = null;
found = 1;
}
if(Line!=null){
Line = readBuffer.readLine();
counter = counter + 1;
}
}
if(found == 1){
textPane.setSelectionStart(CurrentText.indexOf(textToFind) - counter);
textPane.setSelectionEnd(CurrentText.indexOf(textToFind) + textToFind.length() - counter);
int counter2 = 1;
while(counter2!=textToFind.length()){
Replacer = Replacer + "¥";
counter2 = counter2 + 1;
}
CurrentText = CurrentText.replaceFirst(textToFind, Replacer);
findCounter = 1;
}
else{
optionPane.showMessageDialog(null, "No Matches.", "Message", 0);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(NullPointerException e){
optionPane.showMessageDialog(null, "No Matches.", "Message", 0);
}
}
}
else{
int counter = 0;
readtext = new StringReader(CurrentText);
readBuffer = new BufferedReader(readtext);
try {
String Line = readBuffer.readLine();
int found = 0;
while(Line!=null || found != 1){
if(Line.contains(textToFind)){
Line = null;
found = 1;
}
if(Line!=null){
Line = readBuffer.readLine();
counter = counter + 1;
}
}
if(found == 1){
textPane.setSelectionStart(CurrentText.indexOf(textToFind) - counter);
textPane.setSelectionEnd(CurrentText.indexOf(textToFind) + textToFind.length() - counter);
CurrentText = CurrentText.replaceFirst(textToFind, Replacer);
}
else{
optionPane.showMessageDialog(null, "No Matches.", "Message", 0);
}
}
catch(IOException e){
e.printStackTrace();
} catch(NullPointerException e){
optionPane.showMessageDialog(null, "No Matches.", "Message", 0);
}
}
}
2
JFindReplace 도구가 있습니다. 바꾸기를 사용 중지하고 찾기 만하면됩니다. 그것 외에 나는 그것이 얼마나 좋은지를 모른다.
관련 문제
- 1. 스칼라에서이 Java 메커니즘을 구현하는 방법은 무엇입니까?
- 2. appserver에서 확장 메커니즘을 구현하는 방법은 무엇입니까?
- 3. 배율 및 투명도 효과가있는 이미지 스크롤 메커니즘을 구현하는 방법은 무엇입니까?
- 4. 이 메커니즘을 구현하는 방법 :
- 5. JTextPane에서 이미지를 추가하는 방법은 무엇입니까?
- 6. CLISP에서 시간 제한 실행 메커니즘을 구현하는 방법은 무엇입니까?
- 7. "Update App"메커니즘을 구현하는 방법
- 8. 텍스트 선택을 구현하는 방법은 무엇입니까?
- 9. 빌드 브레이크를 찾기 위해 자동화 된 메커니즘을 설정하는 방법은 무엇입니까?
- 10. JTextPane에서 텍스트 커서 크기 변경
- 11. 로그를 구현하는 방법은 무엇입니까?
- 12. JTextPane에서 내용을 맨 아래로 스크롤하는 방법은 무엇입니까?
- 13. AIR에서 이벤트 알림 메커니즘을 구현하는 방법
- 14. 반복적 인 대체 메커니즘을 구현하는 디자인 패턴
- 15. iPad에서 텍스트 음성 기능을 구현하는 방법은 무엇입니까?
- 16. 텍스트 상자에서 자동 저장을 구현하는 방법은 무엇입니까?
- 17. Jtextpane에서 텍스트를 클릭 할 수있게 만드는 방법은 무엇입니까?
- 18. IDEA를 구현하는 방법은 무엇입니까?
- 19. JTextPane에서 서식있는 텍스트를 HTML로보기
- 20. JTextPane에서 선택하는 방법
- 21. C#에서 Excel 해 찾기 기능을 구현하는 방법은 무엇입니까?
- 22. 텍스트 변경시 JEditorPane에서 구현하는 방법
- 23. 파일에서 텍스트 찾기 (C#)
- 24. SSL을 사용하지 않고 jQuery와 WCF간에 간단하고 안정적인 보안 메커니즘을 구현하는 가장 좋은 방법은 무엇입니까
- 25. 최대 절전 모드로 서버 관리 환경에서 연결 풀링 메커니즘을 구현하는 방법은 무엇입니까?
- 26. JTextPane에서 오프셋의 표시 위치 (x, y)를 찾는 방법은 무엇입니까?
- 27. Java 코드를 사용하여 JTextPane에서 단락 기호를 보는 방법은 무엇입니까?
- 28. 중첩 열을 구현하는 방법은 무엇입니까?
- 29. JTextPane에서 단어 줄 바꿈을 구현하는 방법과 공백없이 줄 바꿈을 만들려면 어떻게해야합니까?
- 30. 인증을 구현하는 방법은 무엇입니까?
좋은 것 같다 - 내가 살펴 보겠습니다. 10 배! – SharonBL