I need autocomplete  for search for words in a txt. file

i am not so good in java.
I have a running code for search in text with a txt. file (from user bluefox815).
But I need a solution with autocomplete for search for words in a txt. file.
test_file.txt (Teil des Inhaltes):
Roboter robots
Mechatronik mechatronics
and so on
Can you help me please.
Here is the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
* this program searches for a string in a text file and
* says which line it found the string on
public class SearchText implements ActionListener {
private String filename = "test_file.txt";
private JFrame frame;
private JTextField searchField;
private JButton searchButton;
private JLabel lineLabel;
private String searchFor;
private BufferedReader in;
public SearchText() {
frame = new JFrame("SearchText");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
searchField = new JTextField(80);
searchButton = new JButton("Search");
// this is used later in our actionPerformed method
searchButton.setActionCommand("search");
// this sets the action listener for searchButton, which is the current class
// because this class implements ActionListener
searchButton.addActionListener(this);
lineLabel = new JLabel("nach dem Fachbegriff suchen");
public void createGUI() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
JPanel bottomPanel = new JPanel();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
topPanel.add(searchField);
topPanel.add(searchButton);
bottomPanel.add(lineLabel);
mainPanel.add(topPanel);
mainPanel.add(bottomPanel);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setVisible(true);
public void actionPerformed(ActionEvent e) {
// now we get the action command and if it is search, then it is the button
if ("search".equals(e.getActionCommand())) {
searchFor = searchField.getText();
searchTheText();
private void searchTheText() {
// I initialize the buffered reader here so that every time the user searches
// then the reader will start at the beginning, instead of where it left off last time
try {
in = new BufferedReader(new FileReader(new File(filename)));
} catch (IOException e) {
String lineContent = null;
int currentLine = 0;
// this will be set to true if the string was found
boolean foundString = false;
while (true) {
currentLine++;
// get a line of text from the file
try {
lineContent = in.readLine();
} catch (IOException e) {
break;
// checks to see if the file ended (in.readLine() returns null if the end is reached)
if (lineContent == null) {
break;
if (lineContent.indexOf(searchFor) == -1) {
continue;
} else {
lineLabel.setText(String.valueOf(lineContent));
foundString = true;
break;
if (!foundString)
lineLabel.setText("Es kann kein Fachbegriff gefunden werden.");
try {
in.close();
} catch (IOException ioe) {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SearchText().createGUI();
}

Markus1 wrote:
But I need a solution with autocomplete for search for words in a txt. file.What is your question? What have you tried so far? What are you having difficulty with?
Mel

Similar Messages

  • I need one formatted search for Goods Issue

    Hi Experts
    I need one formatted search for Goods Issue
    ex. I have Issued One item  on 20/07/2011
      In Goods Issue Line Level one column LstIssDt 
    when i issue for the first Item  My document Date Will be my Ige1.LstIssDt(LastIssueDate)(linelevel)
    Now
    the Same Item Iam issuing on 23/07/2011 
    Now  In Goods Issue Line Level   LstIssDt column  shud come as 20/07/2011 when i click formatted search
    Similarly For all the Other Items
    can anyone help me in these
    Thanks  & regards
    Jenny
    Edited by: Jennifer Anderson on Jul 23, 2011 7:57 AM

    Hi Jenifer.....
    I think it should work as it is working on my DB
    Select Top 1 T0.U_LstIssDt From IGE1 T0 Where T0.ItemCode=$[IGE1.ItemCode.0]
    Order By T0.U_LstIssDt DESC
    Do execute this just save and Apply this on Goods Issue for. So when you select the Item this will bring the Last Issue Date of this Particular Item on which field you applied this FMS.......
    Is that an UDF of Last Issue Date or standard field?
    I modified above FMS and please now try.....
    Regards,
    Rahul

  • How to search a special string in txt file and return it's position in txt file?

    How to search a special string in txt file and return it's position in txt file?

    I just posted a solution for a similar question here:  http://forums.ni.com/ni/board/message?board.id=170​&view=by_date_ascending&message.id=362699#M362699
    The top portion can search for the location of a string, while the bottom portion is to locate the position of a character.  Both can search for a character.
    The position of the character within the file is displayed in the indicator(s).
    R

  • Finding words in a txt file!

    Hi guys,
    I have to write a program that opens a .txt file and looks for a specific word in the file and then prints out the entire line that word appears in. I have to use a String Tokenizer? I don't know how to write the program. All I have so far is a program that prints the entire txt document (or each line). I think String Tokenizer is involved in here somewhere but I don't know how to use it.
    import java.io.FileReader;
    import java.util.StringTokenizer;
    import java.io.*;
    public class Find
         public static void main (String[] args) throws IOException
              String line;
              String name;
              String file="find.txt";
              StringTokenizer tokenizer;
              FileReader x = new FileReader (file);
              BufferedReader inFile = new BufferedReader (x);
              line = inFile.readLine();
              while (line != null)
                   tokenizer = new StringTokenizer (line);
    word = tokenizer.nextToken("word");
                   System.out.println (line + "\n");
                   line = inFile.readLine();
              inFile.close();
    The text file Find.txt just has a few lines of text in it.
    I want to make it so that I can look for a specific word in the text file and the resulting printout will be the entire line that the word appears in.
    Any help would be great! Thanks!

    Your first post is very close to what you want:
    import java.io.FileReader;
    import java.util.StringTokenizer;
    import java.io.*;
    public class Find
         public static void main (String[] args) throws IOException
         String line;
         String name;
         String file="find.txt";
         StringTokenizer tokenizer;
         FileReader x = new FileReader (file);
         BufferedReader inFile = new BufferedReader (x);
         line = inFile.readLine();
         while (line != null)
              tokenizer = new StringTokenizer (line);
              String word = tokenizer.nextToken();
              if (word.equals("word")) // we are searchig for the String word
                   System.out.println ("found it! "+line + "\n");
              line = inFile.readLine();
         inFile.close();
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Tell me Logic for search for duplicate words(or strings) in a large file.

    Search for duplicate words (or strings) in a text file containing one word per line. For each word that occurs more than once in the flat file output should be as follows
    <word> <number of occurrences> <line numbers in the file where the word occurs>
    For example, if the word Hello occurs thrice in a file at lines 100, 178 and 3456 the output should read
    Hello, 3, [100, 178, 3456]

    Incidentally i wrote similar code some days back. You need to do some modifications to get the exact output you want, but i hope it will be of some help.
    One more thing its written using JAVA5
    public class Test
         private static final String COLLECTIONS_TEXT = "C:\\Documents and Settings\\amrainder\\Desktop\\Collections.txt";
         public static void main(String[] args) throws IOException
              findDuplicateWords();
         private static void findDuplicateWords() throws IOException
              Collection<String> words = new LinkedHashSet<String>();
              File file = new File(COLLECTIONS_TEXT);
              StreamTokenizer streamTokenizer = new StreamTokenizer(new FileReader(file));
              int token = streamTokenizer.nextToken();
              while(token != StreamTokenizer.TT_EOF)
                   if(token == StreamTokenizer.TT_WORD)
                        words.add(streamTokenizer.sval);
                   token = streamTokenizer.nextToken();
              System.out.println(words);
    }Cheers,
    Amrainder

  • Help needed in Inbox search for Custom attribute

    Hi,
    We have  a requirement where in we are having a custom attribute on Service request to store the ECC Order number.
    We have enhanced the Inbox search to retreive all the service requests havig the ECC order number. 
    Here we are encountering a problem. i just created a new crm service request and entered order number 1234. and now when i search for the same in Inbox search giving the criteria order number as 1234. I get no results found. But when i extend the max list to 2000, then i see the service request appearing in the result list. not sure about the algorithm that is designed for inbox search.
    Any pointers on how to resolve this issue would be of great help.
    Thanks,
    Udaya

    Hi,
    I do not have the time to research this completely, but I had a short look into the class you posted.
    In the GET_DYNAMIC_QUERY_RESULT there is a call to CL_CRM_QCOD_HELPER->PREPROCESS( )
    A little bit lower there are blocks marked by comments for the single searches that are handled by this class. I had a look into the campaign_serach() method. There if you scroll a little bit down (around line 123) they set all search parameters to SIGN = 'I' OPTION = 'EQ'. This is done several times below as well.
    Set a breakpoint in the proprocess() method and check which of the blocks is called and how they handle your search criteria.
    Hope it helps.
    cheers Carsten

  • Need itunes to search for music!!

    I can't figure out how to get itunes to search my hard drive for music. Since all kinds of problems with installing new version (old one wiped out entirely) finally got it to open, (two months later) now there's almost no music. Two 50 cent albums, nothing else. None of the good stuff.
    My stuff is still on windows media player (thank god for Microsoft). How do I get itunes to look for it and copy it to itunes? (Like the old version did!!!)
    Thanks.

    Hello dis-appointed,
    In the Help for iTunes for Mac, the following answer comes up to the query “Search for files”. I suspect that the second one will be the most relevant for you. I presume you can do that via the “Find” facility from the Start menu.
    I agree that it would be good to be able to search in the way that the older versions did.
    Quoted from iTunes Help for Mac
    Here are ways to make your songs appear in the library again:
    • In the Finder, drag your iTunes Music folder to the iTunes window. You will see the songs in your library again, but not playlists, song ratings, or other information you created.
    • If that doesn't work, your songs may be elsewhere on your hard disk. In the Finder, choose File > Find and search for a song by title or artist. Or search for "MP4" to find files downloaded from the iTunes Store or "MP3" to find songs encoded in MP3 format. Drag songs (or folders containing songs) to the iTunes window to add the songs to iTunes again.
    Best of luck,
    Martin
    If you found that this contribution helped to answer your question, please consider awarding some points. Why reward points?
    Powerbook 15-inch G4 1GHz   Mac OS X (10.4.8)   Several veterans that go on and on. 40gig, 3rd generation iPod

  • Utility VI for searching for the occurance of a string in all files in a directory

    Is anyone aware of a utility VI that can search for a string(s) in all
    file types such as doc, xls, ppt etc in a specified directory?

    Greetings,
    I'm having an issue (using 8.5) with a directory read in. I've attached my elementary VI. Basically I want to read in mutliple files (they will be the same array size), and analyze each file. I am confident I will be able to analyze the data as necessary, I'm just having a problem parsing the data. Verbally I know exactly what I need to do just doesn't seem to be working in labview. Reading in the directory isn't the hard part, but breaking up the 2D data into the number of files I have apparently is for me. 
    1. Read in (user defined) directory
    2. List the file names | # of files in the directory
    3. Perform MAX value and % analysis of data on AMP array 
    Any help would be greatly appreciated. Even if it's just verbally pointing me in the right direction. I've attached the VI and 3 example data files I read in.
    Thanks in advance...I really feel like I should know this one, but I usually deal in individual files, this is my first directory read.
    Best Regards,
    Chazzzmd 
    Attachments:
    labview text upload.zip ‏33 KB

  • JSP/Servlet code for searching for Domain availability

    Hi Guys
    I am giving a service on my homesite which will search for the domain availability. Users will enter the domain name and the code should check whether the domain is already taken or it is available for registration
    Please help me out.

    Nah, I don't have one myself. WHOIS can work but only for .org, .net and .com (and a few others here and there.) In that case, all you'd have to do is run the command, and look for the text which says it isn't registered..
    trejkaz@carroll:~> whois gnifodgjidfo.com
    [whois.crsnic.net]
    Whois Server Version 1.3
    Domain names in the .com, .net, and .org domains can now be registered
    with many different competing registrars. Go to http://www.internic.net
    for detailed information.
    No match for "GNIFODGJIDFO.COM".
    Last update of whois database: Sun, 25 Nov 2001 16:58:31 EST <<<The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains and
    Registrars.

  • Need help to add the words in a text file to an arraylist

    I am new to java and I really need some help for my project.I want to add the words of a text file to an arraylist. The text file consist of words and the following set of punctuation marks {, . ; : } and spaces.
    thanks in advance :-)

    I/O: [http://java.sun.com/docs/books/tutorial/essential/io/index.html]
    lists and other collections: [http://java.sun.com/docs/books/tutorial/collections/index.html]

  • Correct values for DefaultExportPath option in Disco pref.txt file

    Hi All,
    I am trying to edit the "DefaultExportPath" parameter in Disco pref.txt file file. We are using Discoverer Plus and Viewer on CP4 and are using JVM1.5 or higher.
    I referred to Metalink Doc Id: 365245.1 and Oracle Configuration Guide doc B13918_03.
    I am interested in making the local system desktop as the default export location for all the users with no exceptions.
    Tried to edit the parameter values to
    DefaultExportPath = "C:\Documents and Settings\<Windows user name>\Desktop"
    but it didn't work.
    Also came across Metalink Doc Id: 438598.1 which talks about changing individual systems "deployment.properties" file which I don’t want to get into. It’s too much of over head.
    I am looking for some pointer so that we can edit the pref.txt file to change the default location to the desktop universally across all the users.
    Any help is appreciated.
    Thanks.

    Hi Rod,
    Thx for the update.
    Just one more dumb questions. Is there an automated way of changing these properties. Physically changing them would be vey tough since quiet a few of our users work remotely.
    Thanks.

  • Tagging words through a .txt file

    Hi all,
    We have been looking all over the internet for a script that we can use/buy. But cannot find it anywhere.
    We have a rather large document and an external word list in a .txt file. This list contains words that need to be in the index at the end of the document.
    Instead of filling in a couple of hundred words and linking them by hand, it would be great if there is a script that can handle this.
    We have looked in to Indexmatic2 (http://www.indiscripts.com/post/2011/07/indexmatic-2-public-release-and-user-s-guide ), but this script generates its own index list and does not create links to the original words in the document.
    We have found a script that can create index links from colored words in the document.
    So does anyone know if there is a script floating around that can load an external .txt wordlist and either color or add a character style to words in a document?
    Or even a script that does what we need in 1 go?
    Thanks

    Thedesmodus,
    there is a script by Martin Fischer at www.hilfdirselbst.ch (a swizz-german website) that could fit your needs. You can download it if you choose to be a premium member which requires a small fee. It's written for InDesign CS3 but it should run with CS4 or CS5. I tested it with a small list of words and it ran fine with InDesign CS5.
    http://indesign.hilfdirselbst.ch/text/indexeintrage-mit-unterstichworten-uber-eine-konkord anzdatei-erzeugen.html
    If you prefer a Google translation:
    http://translate.google.de/translate?hl=de&sl=de&tl=en&u=http%3A%2F%2Findesign.hilfdirselb st.ch%2Ftext%2Findexeintrage-mit-unterstichworten-uber-eine-konkordanzdatei-erzeugen.html
    Uwe

  • How to read Chinese word from a TXT file

    File.OpenText() read a TXT File with  Chinese word in   ;but it not show right.
    exam:The TXT File include :中国
     this.Txt1.Text=ofd.File.OpenText().ReadToEnd();
    but it show :��ʹ�ݼƻ��
    How to solve it

    What encoding does the text file use?  Unlike .NET, Silverlight only supports UTF-8 and UTF-16.  File.OpenText() uses UTF-8 by default.
    If the text file is in some other encoding, you can create your own encoding class (that derives from System.Text.Encoding) that can be used to read the text file.
    class MyEncoding : System.Text.Encoding {
    this.Txt1.Text = (new StreamReader(ofd.File.OpenRead(), new MyEncoding())).ReadToEnd();
    Regards,
    Justin Van Patten
    Program Manager
    Common Language Runtime

  • I need help with searching for an image inside another image

    I need to write a program that checks for a specific image (a jpg) inside another, larger, image (a jpg). If so, it returns a value of true. Can anyone help me?
    Winner takes all. First person to solve this gets 10 dukes.
    Please help.

    Hi,
    I would use a full screen image Sequence made with png for transparency and put your article behind. no auto play, stop at first and last image. and information for swipe to display article.

  • Best Practices for Placing Microsoft Word (doc or docx) Files?

    What is the best way to place Word files into InDesign CS3?
    Every time I place a Word file into InDesign, ID applies unwanted character styles and paragraph overrides to all of my text. For example, if I place a Word document with "Pal-Body" as the paragraph style, ID places the text with the *character* style "Pal-Bold" applied to all of the text, and ID applies an override to all of the paragraphs to remove the bold.
    Essentially, the text almost looks correct since the paragraph override undoes the bold caused by the unwanted character style. But "almost correct" is not good enough, so I have to manually remove the override, remove the character styles, and reapply any character styles to the text that are supposed to be there.
    This happens regardless of whether I select "Use InDesign Style Definition" or map the styles from Word to InDesign.
    By the way, my styles in Word are exactly the same as InDesign. I saved my InDesign template as an RTF file, and then saved that as a DOT Word Template.
    Also, I didn't seem to have this problem with InDesign CS2.
    What is going on and how do I fix it?

    There are a bunch of reasons why you might get paragraph overrides on imported text. In my case, it's because Word appends styling information for all complex & Asian text to my styles exported from ID. When I place the revised (or translated) RTF, I get paragraph overrides. I just clear 'em all at once. It almost always snaps back to the specs I set in my original ID doc.
    Every once in a while, I'll get some Normal or some auto-named Word style gibberish in my ID doc; it's usually faster to go and fix the styling in Word and re-import than it is to try to fix it in ID.
    What happens when you select all text and clear all overrides? If you don't get what you want, then probably new style info is being auto-generated while you work in Word. To test this: Export your RTF, and then place it again without opening it up in Word. If you don't find any paragraph overrides when you do this, then you can assume that the way you're working in Word is causing this. When I roundtrip through Word in this way, I always examine my styling before saving and placing, and there's always something to fix.
    Also, you don't want "Available Styles" you want "Formatting in use." It's a dropdown at the bottom of the sidebar in Word. That will hide "Normal," if that style does not appear in your doc.

Maybe you are looking for