473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to create a textarea and append the list to it?

I have to create a textarea and if i have typed any character in the textarea it has to check in the dictionary.jar file and it has to display the related words in the list attached to that textarea
Dec 7 '12 #1
4 2285
gits
5,390 Expert Mod 4TB
what have you done so far? please post that code - so that we have something to work with.
Dec 7 '12 #2
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2.  
  3. import org.languagetool.JLanguageTool;
  4. import org.languagetool.Language;
  5. import org.languagetool.rules.RuleMatch;
  6.  
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import java.io.IOException;
  10. import java.util.List;
  11.  
  12. public class Check implements KeyListener {
  13.     private JFrame f; // Main frame
  14.     private JTextArea ta, tSuggest; // Text area
  15.     private JScrollPane sbrText, suggestionsText; // Scroll pane for text area
  16.     private JButton btnQuit; // Quit Program
  17.  
  18.     private Object language;
  19.     private JLanguageTool langTool;
  20.  
  21.     public Check() { // Constructor
  22.         // Create Frame
  23.         try {
  24.             langTool = new JLanguageTool(Language.AMERICAN_ENGLISH);
  25.             langTool.activateDefaultPatternRules();
  26.         } catch (IOException e1) {
  27.             e1.printStackTrace();
  28.         }
  29.         f = new JFrame("Enter the text");
  30.         f.getContentPane().setLayout(new FlowLayout());
  31.  
  32.         // Create Scrolling Text Area in Swing
  33.         ta = new JTextArea("", 10, 50);
  34.         ta.setLineWrap(true);
  35.  
  36.         tSuggest = new JTextArea("", 10, 50);
  37.         tSuggest.setLineWrap(true);
  38.         sbrText = new JScrollPane(ta);
  39.         sbrText
  40.                 .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  41.         ta.addKeyListener(this);
  42.  
  43.         suggestionsText = new JScrollPane(tSuggest);
  44.         suggestionsText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  45.  
  46.         // Create Quit Button
  47.         btnQuit = new JButton("Quit");
  48.         btnQuit.addActionListener(new ActionListener() {
  49.             public void actionPerformed(ActionEvent e) {
  50.  
  51.                 System.exit(0);
  52.             }
  53.         });
  54.  
  55.     }
  56.  
  57.     public void keyTyped(KeyEvent e) {
  58.     }
  59.  
  60.     public void keyReleased(KeyEvent e) {
  61.     }
  62.  
  63.     public void keyPressed(KeyEvent e) {
  64.         if (e.getSource() == ta) {
  65.             if ((e.getKeyCode() == KeyEvent.VK_SPACE)
  66.                     || (e.getKeyCode() == KeyEvent.VK_ENTER)) {
  67.                 String text = ta.getText();
  68.                 int lastWordPos = text.trim().lastIndexOf(" ") + 1;
  69.                 //System.out.println(text.substring(lastWordPos));
  70.                 tSuggest.setText(text.substring(lastWordPos)+"\n");
  71.  
  72.                 List<RuleMatch> word=null;
  73.                 try {
  74.                     word = langTool.check(text);
  75.                 } catch (IOException e1) {
  76.                     // TODO Auto-generated catch block
  77.                     e1.printStackTrace();
  78.                 }
  79.  
  80.                 for (RuleMatch match : word) {
  81. //                    System.out.println("Potential error at line "
  82. //                            + match.getEndLine() + ", column "
  83. //                            + match.getColumn() + ": " + match.getMessage());
  84. //                    System.out.println("Suggested correction: "
  85. //                            + match.getSuggestedReplacements());
  86.  
  87.                     tSuggest.setText(tSuggest.getText()+"\n"+"Potential error at line "
  88.                             + match.getEndLine() + ", column "
  89.                             + match.getColumn() + ": " + match.getMessage());
  90.                     tSuggest.setText(tSuggest.getText()+"\n"+"Suggested correction: "
  91.                             + match.getSuggestedReplacements());
  92.                 }
  93.             }
  94.         }
  95.     }
  96.  
  97.     public void launchFrame() { // Create Layout
  98.         // Add text area and button to frame
  99.         f.getContentPane().add(sbrText);
  100.         f.getContentPane().add(suggestionsText);
  101.         f.getContentPane().add(btnQuit);
  102.  
  103.         // Close when the close button is clicked
  104.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  105.  
  106.         // Display Frame
  107.         f.pack(); // Adjusts frame to size of components
  108.         f.setVisible(true);
  109.     }
  110.  
  111.     public static void main(String args[]) {
  112.         Check gui = new Check();
  113.         gui.launchFrame();
  114.     }
  115. }
Dec 7 '12 #3
gits
5,390 Expert Mod 4TB
you want to create a webpage or a java-desktop app? in the 2nd case i will move the thread over to the java-forum for you.

regards
Dec 7 '12 #4
Rabbit
12,516 Expert Mod 8TB
Also, you haven't said what the problem is. Are you getting errors? What are they? Is it not doing what you expect? What is it doing instead?
Dec 7 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: egelendu | last post by:
How to create email distribution list in yahoo mail?
1
by: cppaddict | last post by:
Hi, How can you create a pointer or a reference to a list. For example: list<int> l; //...some code initializes the list //now try to create a pointer or ref to it list<int>* = l; //doesn't...
1
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've...
0
by: Dica | last post by:
i'm just trying out c# and VS 2003 for the first time and i'm running into an error: "Cannot create a child list for field tblProjects" the section of code that seems to be throwing this is:...
1
by: Agnes | last post by:
Please be kind to take a look dsSeaInvInfo.Clear() daSeaInvInfo.SelectCommand = New SqlCommand daSeaInvInfo.SelectCommand.Connection = conSea daSeaInvInfo.TableMappings.Add("Table",...
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
1
Jezternz
by: Jezternz | last post by:
Scriptaculous needs an official forum but does not have one so I am asking here :). note you will need to be familiar with scriptaculous to help me here. Basicly I have a script that has a...
2
jonthysell
by: jonthysell | last post by:
I have a list as an attribute of a class. I need to be able to intercept any add/remove of objects to the list, so that I can perform cleanup on other attributes of the class. Currently, I'm...
0
by: timr30017 | last post by:
For days now I've been trying to create a Distribution List in Outlook from my VB.net app. I can create one but I cannot put any members in it because there seems to be no way to define and create a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.