BufferedReader or writer around a textarea

Is there a way to wrap a bufferedReader or writer around a textarea?

i would wait for an enter KeyEvent and then do the write then.
public void keyPressed(KeyEvent e){
   if( e.getKeyCode == KeyEvent.VK_ENTER ){
       out.write( textArea.getText() );
       textArea.setText("");
}

Similar Messages

  • Write Arabic in textarea

    plese help
    how can i write arabic in text area

    Do you setup the international version of JDK ?
    we can input Japan, korea and Chinese to TextArea..
    peterx
    Pivotonic Inc. http://www.pivotonic.com
    1. java IDE tool : JawaBeginer
    2. java jar tool : JavaJar

  • Struts "bean:write" in "html:textarea"

    Hi,
    i want to write a bean with bean:write to a html:textarea
    how can i do this?

    Hint:
    <html:textarea ...>
        <bean:write ... />
    </html:textarea>

  • Border around a TextArea

    How would i go about adding a border (just a black line) around a JtextArea?

    Just like around any other JComponent for a standalone JTextarea -- however, if it's in a JScrollPane, you'll need to set the border to the ScrollPane's Viewport.

  • How can I set down the UIScrollBar of my TextArea?

    Hello world...
    I have a little problem:
    I have a TextArea for a Chat. When I write a lot, the UIScrollBar remains on the top of my TextArea...
    I'd like my UIScrollBar is located at the bottom of TextArea...
    Can someone help me?
    Thanks.
    Emiliano.

    Try using the following code after each time you write to the TextArea.  I am assuming you are using a TextArea component and are trying to control the position of where it is scrolled to when it refreshes with the chat data.
    "ta" is the instance name of the TextArea
    ta.verticalScrollPosition = ta.maxVerticalScrollPosition;

  • TEXTAREA problem in IE...

    Hi All,
    We are using Internet Explorer version 6.0.2800.1106 on Windows 2000 Professional SP4.
    Our JSP page has around 50 TextArea components in form. And each TextArea component has around
    150 bytes of data entered. When we try to submit the page it gives Error prompt "A runtime error has occurred . Do you want to debug ?... Invalid Syntax. " . Any idea about this problem and how to resolve it ? IS there any restrictions on the TextArea componenet size in IE ? Same page works fine with Mozilla FireFox browser.
    Regards,
    Ronak

    Is your HTML formatted properly? there's no data size, in particular, for textarea. Is that error a Javascript error or the browser crashing?

  • Linking Editing TextArea with Button Handler

    Java newbie here,i am trying to create a program to display a keyboard on screen and display the the letter in a text area when the character letter is pressed. And the complete sentence when return is pressed.
    I have the GUI up, the problem is the letters are dispayed in a JOptionPane and i want them to be written to the TextArea.
    Any help would be appreaciated
    Here is the code in full so far.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    * Alphabet is a program that will display a text pad and 27 buttons of the 25
    * Letters of the Alphabet and display them when pressed and display all buttons
    * when Return button is pressed..
    * version (V 0.1)
    public class Alphabet extends JFrame
        private JPanel buttonPanel  ;
        private JButton buttons[];
        private JButton SpaceButton;
        private JButton ReturnButton;
        //setup GUI
        public Alphabet()
        super("Alphabet");
        //get content pane
        Container container = getContentPane();
        //create button array
        buttons = new JButton[122];
        //intialize buttons
        SpaceButton = new JButton ("Space");
        ReturnButton = new JButton ("Return");
        //setup panel and set its layout
        buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout (7,buttons.length));
        //create text area
        JTextArea TextArea = new JTextArea ();
       TextArea.setEditable(false);
       container.add(TextArea, BorderLayout.CENTER);
       // set a nice titled border around the TextArea
        TextArea.setBorder(
          BorderFactory.createTitledBorder("Your Text is Displayed Here"));
      //create and add buttons
        for (int count = 96; count <buttons.length; count++ ) {
        buttons[count] = new JButton( ""+ (char)(count +1 ));
        buttonPanel.add(buttons [count]);
        ButtonHandler handler = new ButtonHandler();
        buttons[count].addActionListener(handler);
        buttonPanel.add(SpaceButton);
       buttonPanel.add(ReturnButton);
       ReturnButton.setToolTipText( "Press to Display Sentence" ); 
         container.add(buttonPanel, BorderLayout.SOUTH);
        // set a nice titled border around the ButtonPanel
        buttonPanel.setBorder(
          BorderFactory.createTitledBorder("Click inside this Panel"));
            // create an instance of inner class ButtonHandler
              // to use for button event handling              
              ButtonHandler handler = new ButtonHandler(); 
              ReturnButton.addActionListener(handler);
            setSize (625,550);
            setVisible(true);
    }// end constructor Alphabet
    public static void main (String args[])
        Alphabet application = new Alphabet();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // inner class for button event handling
         private class ButtonHandler implements ActionListener {
              // handle button event
             public void actionPerformed( ActionEvent event )
                 JOptionPane.showMessageDialog( Alphabet.this,
                    "You pressed: " + event.getActionCommand() );
    }//END CLASS ALPHABET

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class Alphabet extends JFrame
    private JPanel buttonPanel ;
    private JButton buttons[];
    private JButton SpaceButton;
    private JButton ReturnButton;
    JTextArea TextArea;
    String str="";String stt="";
    //setup GUI
    public Alphabet()
    super("Alphabet");
    //get content pane
    Container container = getContentPane();
    //create button array
    buttons = new JButton[122];
    //intialize buttons
    SpaceButton = new JButton ("Space");
    ReturnButton = new JButton ("Return");
    //setup panel and set its layout
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout (7,buttons.length));
    //create text area
    TextArea = new JTextArea ();
    TextArea.setEditable(false);
    container.add(TextArea, BorderLayout.CENTER);
    // set a nice titled border around the TextArea
    TextArea.setBorder(
    BorderFactory.createTitledBorder("Your Text is Displayed Here"));
    //create and add buttons
    for (int count = 96; count <buttons.length; count++ ) {
    buttons[count] = new JButton( ""+ (char)(count +1 ));
    buttonPanel.add(buttons [count]);
    ButtonHandler handler = new ButtonHandler();
    buttons[count].addActionListener(handler);
    buttonPanel.add(SpaceButton);
    buttonPanel.add(ReturnButton);
    ReturnButton.setToolTipText( "Press to Display Sentence" );
    container.add(buttonPanel, BorderLayout.SOUTH);
    // set a nice titled border around the ButtonPanel
    buttonPanel.setBorder(
    BorderFactory.createTitledBorder("Click inside this Panel"));
    // create an instance of inner class ButtonHandler
    // to use for button event handling
    ButtonHandler handler = new ButtonHandler();
    ReturnButton.addActionListener(handler);
    SpaceButton.addActionListener(handler);
    setSize (625,550);
    setVisible(true);
    }// end constructor Alphabet
    public static void main (String args[])
    Alphabet application = new Alphabet();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // inner class for button event handling
    private class ButtonHandler implements ActionListener {
    // handle button event
    public void actionPerformed( ActionEvent event )
              if((event.getActionCommand()).equals("Space")){
                   TextArea.setText(event.getActionCommand());
                   str+=" ";
                   //TextArea.append(" ");
              else if((event.getActionCommand()).equals("Return")){
                   stt+=str;
                   stt+="\n";
                   str="";
                   TextArea.setText(stt);
                   //TextArea.append(str);
                   //TextArea.append("\n");
              else {
                   TextArea.setText(event.getActionCommand());
                   str+=event.getActionCommand();
                   //TextArea.append(event.getActionCommand());
    }//END CLASS ALPHABET
    Ok?

  • Limited characters in textarea using swings

    Hi,
    i have one text area that is created using swings technologies now this text area need to allow only 30 characters perline and limit of the text area is maxmium of 500 characters.
    i have done some coding but it breaks whenever the copy/paste happens(i.e it allowing more than 30 characters perline).Can anybody provide the solution ASAP.
    Thanks in advance

    1. This question should go into the swing forum.
    2. Write your own TextArea (extends JTextArea). In this class get the document with
    AbstractDocument doc = (AbstractDocument)this.getDocument();Then write your own Document filter (extends DocumentFilter) and set this filter to the document
    doc.setDocumentFilter(filter)In the filter you have full control over of what is inserted in your text area.

  • Is write mode faster than append mode?

    Hi All,
    I have to write some data after selecting from a table. I have to call six procedure to write data. Each of the procedure writes around 100-150MB data.
    If I generate six files in write mode it takes around 11 minutes. (using utl_file.fopen('/tmp','csv','w');)
    but if i generate 1 file (combining all) using (using utl_file.fopen('/tmp','csv','a');) It has passed 55 minutes an size of file is still around 500 MB and still growing.
    Can anyone explain why append is so slow comapred to write ? or there is any other reason .. note that we have lot of space on server.
    Regards,
    Amit

    What you've written does not compute.
    On my laptop I can write that much data far faster than what you've indicated you are seeing.
    What version number?
    How is the data being selected?
    How much time does the SELECT take without the WRITE?
    When I have large amounts of data to write my method of choice is to concatenate them into a CLOB and then write it out using DBMS_ADVISOR.CREATE_FILE
    http://www.morganslibrary.org/reference/dbms_advisor.html

  • BufferedReader (help me....... please ^_^)

    can anyone help me? we just got this problem in java programming and i'm kinda stuck. i can only do up to the reading of the .txt file using BufferedReader.
    "Write a program that reads from an input file an M by N grid of letters and a list, L, of words, and, for each word, W, in L, finds the row, R, and column, C, in the grid where the word is found."
    i'm not asking for an entire code..... i just want to ask HOW it is done, especially the diagonal words.
    example:
    input:
    8 12
    abcDEFGhiggx
    hEbkWalDorkT
    FtyAwaldORmr
    FtsimrLqsrcE
    byoArBeDeyvb
    KlcbqwikomkG
    strEBGadhrba
    yUiqlxcnBjfD
    4
    Waldorf
    Bambi
    Betty
    Dagbert
    output:
    Waldorf 2 5
    Bambi 2 3
    Betty 1 2
    Dagbert 7 8

    This isn't very complex task once you think it the way you solve a crossword puzzles in real world.
    Once you have the grid of letters and list of words you could start the search by taking the first letter of a word and try to locate it from the grid. When you find it just check if the second letter would be the next at the same line and the third the next after the next and so on. That's for horizontals, for verticals do the same but instead of next check the letter below. For diagonals check the letter one forward and one down.

  • How to select one line in TextArea?

    does anybody know how to click one line in TextArea and get the contents of the line(string)? How can I implement the action?
    any hints would be appreciated.
    thanks in advance.

    The term 'line' might mean a displayed line of text or it might mean text delimited by a newline character.
    If you mean text delimited by a newline character, then sylvain.barbot has an approach that may work. A MouseListener would know when a click occurs and could determine the 'line' of text between \n's from the current Caret position.
    If you mean a displayed line of text, that will be difficult unless you put restrictions on the TextArea. If you allow the TextArea to be resized or use a variable-width font, then I can't think of a way to do what you want. The number of characters per line changes depending on the current size and the character content of the TextArea. You might as well write your own TextArea.
    If you use a fixed-width font, then you should be able to calculate the number of characters per line. With a ComponentListener, you should be able to re-calculate the number of characters per line when the TextArea is resized. It would be easiest if you did not allow resizing of the TextArea and used a fixed-width font. Then getCaretPosition() would give you the position in the whole TextArea and you could calculate the line start and end.

  • Anybody seeing extremely slow write speed (50K/s) over Samba?

    Hello,
    Is there anybody seeing a extremely slow write (around 60 kB/s) on internal/external hard disk of TimeCapsule from a Ubuntu Box(9.10) box mounted as Samba/CIFS? Frustrating!!

    can you pleeeaase give me instructions on how to set up a connection between a TC and Linux. I have been trying to figure this out for a while (being a noob at Linux doesnt help).
    thanks

  • I/O writes

    I work on a product that needs to keep some intermediate transaction information in a file. I've built a persistence mechanism which maps a random access file to objects in memory. But I write to the file whenever there is a change in any of the object's attributes, associations. I use most of the RandomAccessFile methods like writeInt( ), writeLong( ), writeBytes( ) etc.
    The problem i'm finding is, though I write around 250 times per transaction, the PerfMon shows around 4000 I/O writes. I need to optimize the number of writes and even 250 is a high number.
    I've read that in Solaris with JDK1.1 there was a problem that each writeInt( ) was getting translated into 4 write calls. Is this still true with JDK1.3?
    Anyone out there who has faced this problem before or who can help me in pointing out what could be going wrong?

    Using memory-mapped I/O with J2SE 1.4's new java.nio support in FileChannel.map() and MappedByteBuffer should greatly reduce the number of disk writes, provide much higher throughput, and will completely eliminate OS calls from Java for reads and writes. It is almost always faster to let the OS handle the reads and writes by using memory-mapped files.
    Cheers,
    Colin

  • How to do it?  Alternate readLine(), read bytes?

    Problem: How to alternate between an InputStreamReader and a raw InputStream when reading data from an InputStream. The catch is that the InputStreamReader may read ahead a few bytes and so subsequent reading from the underlying InputStream will miss those buffered bytes.
    Background:
    I have an application that communicates with a Tomcat servlet with Http protocol.
    I want to send a request, and receive a response as a Java Object. The problem is receiving the response as a Java Object.
    Actually, I have no problem if I use a URLConnection and create an ObjectInputStream from the URLConnection InputStream. But the URLConnection is very slow to use for uploading large files.
    There is a code project called JUpload which uploads files very fast, at least 10 times as fast as URLConnection. It uses sockets and their input/output streams. So I'm adapting some of that code for my application.
    The problem is that the JUpload code is harder to use. It parses the HTTP headers in both directions. When receiving the response, it parses the HTTP headers using an InputStreamReader wrapped in a BufferedReader to read lines, and continues reading lines for any other responses destined to the application.
    However, I need to read a Java object after the header. Therefore, I need to get the underlying InputStream so I can create my ObjectInputStream.
    There is a conflict here. The BufferedReader may (and does) read ahead, so I can't get a "clean" InputStream.
    I have a workaround, but I'm hoping there is a better way. It is this: After reading the HTTP header lines, I read all the remaining characters from the BufferedReader and write them to a ByteArrayOutputStream wrapped in an OutputStreamWriter. Then I create a new ByteArrayInputStream by getting the bytes from the ByteArrayOutputStream. I then "wrap" my ObjectInputStream around the ByteArrayInputStream, and I can read my Java Object as a response.
    This technique is not only clumsy, but it requires buffering everything in memory after the header lines are processed (which happens to be OK for now as my response Object is not large). It also gets really clumsy if the returned HTTP reponse is chunked, because the BufferedReader is needed alternately to read the chunk headers. Fortunately, I haven't encountered a chunked response.
    It feels like what I need is a special Reader object that allows you to alternately read characters or read bytes without "stuttering" (missing buffered bytes).
    I would think the authors of the URLConnection would have encountered this same problem.
    Any thoughts on this would be appreciated.
    -SB
    Edited by: SB4 on Mar 21, 2010 8:08 PM
    Edited by: SB4 on Mar 21, 2010 8:09 PM
    Edited by: SB4 on Mar 21, 2010 8:10 PM

    Yes, that is the problem as you noted. My solution is to continue reading all the characters from the BufferedReader and to convert them back to a byte stream using the ByteArrayOutputStream, OutputStreamWriter, etc.
    It works, just seems clumsy and not scalable.
    I was hoping there might exist a special "CharByteReader" (invented name) class somewhere that would be like a BufferedReader, but that would implement a read(byte[], offset, length) type of method that could access the read-ahead buffer in the same way the read(char[], offset, length) method does.
    URLConnection is just too slow, including chunked mode.

  • Threads + Swing

    Hi folks,
    I found the following code here at SDN. The main purpose of this code is to execute an exe-file and to redirect its output to a java Swing JTextArea.
    This code works fine. However, if I change...
        public cCallGenerator()
            init();
            initProcess();
        }...to...
        public cCallGenerator()
            init();
            // initProcess(); NOW WE DONT START THE PROCESS HERE
        }and start initProcess() by clicking on the button, the output is NOT(!) redirected to the JTextArea. The exe file is still running.
    I guess that I simply misunderstood the concept of threads in java...
    Can anybody help me?
    Thanks a lot
    Christian
    Here is the code:
    import javax.swing.*;
    import org.dom4j.Document;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.io.*;
    public class cCallGenerator extends JFrame {
        private JTextArea textArea;
        private JTextField textField;
        private PrintWriter writer;
        public cCallGenerator()
            init();
            initProcess();
        public void init()
            textArea = new JTextArea(20, 80);
            textArea.setEditable(false);
            textField = new JTextField(30);
            textField.addKeyListener(new KeyAdapter()
                public void keyPressed(KeyEvent event) {
                    if (event.getKeyCode() == KeyEvent.VK_ENTER)
                        if (writer != null)
                            textArea.setText("");
                            writer.print(textField.getText() + "\r\n");
                            writer.flush();
                            textField.setText("");
            Container container = getContentPane();
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportView(textArea);
            container.add(scrollPane, BorderLayout.CENTER);
            container.add(textField, BorderLayout.SOUTH);
            JButton start = new JButton("Start");
            container.add(start, BorderLayout.WEST);
                                       start.addActionListener(new ActionListener() {
                                            public void actionPerformed(ActionEvent evt) {
                                                 try {
                                                      initProcess();
                                                 } catch(Exception e) {
                                                      JOptionPane.showConfirmDialog(null,
                                                                "The following error occured while trying to generate the configuration file: \n\n" + e.getMessage(),
                                                                "XML Error",
                                                                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);     
                                                      System.exit(1);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            textField.grabFocus();
            setVisible(true);
        public static void main(String[] args) {
            new cCallGenerator();
        public void initProcess()
            Runtime rt = Runtime.getRuntime();
            try
                //Process p = rt.exec(new String [] {"cmd", "/C", textField.getText()});
                //textArea.setText("");
                //textField.setText("");
                Process p = rt.exec("panoratio.exe -g -c output.xml -o output.pdi");
                writer = new PrintWriter(p.getOutputStream());
                Thread thread1 = new Thread(new StreamReader(p.getErrorStream()));
                Thread thread2 = new Thread(new StreamReader(p.getInputStream()));
                thread1.start();
                thread2.start();
                System.out.println("Exit Value = " + p.waitFor());
            catch (Exception ex)
                textArea.append(ex.getMessage());
                ex.printStackTrace();
        public class StreamReader implements Runnable
            InputStream is;
            public StreamReader(InputStream is)
                this.is = is;
            public void run()
                try
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String data;
                    while ((data = reader.readLine()) != null)
                        textArea.append(data + "\n");
                    reader.close();
                catch (IOException ioEx)
                    ioEx.printStackTrace();
    }

    Thanks for your help!
    I still don't really understand why - but if I replace
                thread1.start();
                thread2.start();with
                thread2.start();
                SwingUtilities.invokeAndWait(thread1);it works. So, thanks a lot for your help.
    Bye

Maybe you are looking for

  • Material Master Unit Of Measurement Changes Clarification

    Hi We have a material master with base unit of measurement as FT in basic data 1 view. For this we have already some purchsing documents like PO's and PR's But currently we dont have any open PO (or) PR and stock in system. Still we could not change

  • What version of Acrobat is needed to split pages of a PDF into separate documents? Standard or Pro?

    Need to be able to split PDFs into separate files dependent of what page. Can standard do this? Or will i need Pro?

  • Multiple connection pools problem

    Hi, Here is the problem. We use several connection pools to access differents schema of our database. We also have a connection pool opened for Weblogic Commerce which connects to the Commerce schema in our database. Here is a sample of our weblogic.

  • Set up of IDS

    Hi, I have a good background of IDS and Documaker Development. I wanted to set up IDS for retrieval and Wip Processing in AIX, can somebody guide me with the proper document or the step by step guide for IDS setup

  • Can't see my email

    somehow, the vertical line shifted and my email inbox disapeared. I have tried many ways but no luck. Uninstalled firefox, downloaded new file, installed. Still no inbox. Using att.net for email.