Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:38:34+00:00 2026-06-12T03:38:34+00:00

Working on a project I got into running java applications through a small console-like

  • 0

Working on a project I got into running java applications through a small console-like window. Thanks to the wonderful community in here I managed to solve the problem with outputting the data from a proccess but my command-line applications running will constantly give errors as there is no input stream.

Based on the last helpful reply in that thread I suppose I shall approach similarly the JTextFieldInputStream extends InputStream implementation, but looking in the javadocs and throughout google and the internet for some class that does just that I really found nothing explaining how to do this.

So I am asking for some link, example, tutorial, sample code for it just like in the previous topic.
Give me just a class that extends InputStream and can be extended to read from a JTextField when I press Enter and I will do the rest with implementing this and making it work! Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:38:36+00:00Added an answer on June 12, 2026 at 3:38 am

    How about this implementation

    import java.io.IOException;
    import java.io.InputStream;
    
    import javax.swing.JTextField;
    
    
    public class JTextFieldInputStream extends InputStream {
        byte[] contents;
        int pointer = 0;
    
        public JTextFieldInputStream(final JTextField text) {
    
            text.addKeyListener(new KeyAdapter() {
                @Override
                public void keyReleased(KeyEvent e) {
                    if(e.getKeyChar()=='\n'){
                        contents = text.getText().getBytes();
                        pointer = 0;
                        text.setText("");
                    }
                    super.keyReleased(e);
                }
            });
        }
    
        @Override
        public int read() throws IOException {
            if(pointer >= contents.length) return -1;
            return this.contents[pointer++];
        }
    
    }
    

    to use this input stream, do the following

     InputStream in = new JTextFieldInputStream( someTextField );
     char c;
     while( (c = in.read()) != -1){
        //do whatever with c
     }
    

    does it read only when I hit enter?

    it reads when you call in.read() if the return value -1 it means end of the stream

    (And will I be able to modify so that the Enter key empties the JTextField?)

    you need to add an action listener and this functionality has nothing to do with the job of input stream

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a small project and got into some troubles trying to keep
I've got a Maven build for an OSGI project I'm working on. I'd like
I've got appharbor working currently with github , but the problem I'm running into
I'm working through the Java Ranch Cattle Drive online tutorials and got up to
I'm working on a project for school and am running into some problems I
I'm working on a new iPhone project and I'm running into problems with sqlite.
Im working in a project and I got two types in Date. I want
I've got a project I'm working on and for some reason, I can't get
I installed TeamCity and got it working against my project. However, I have since
I am currently working on a project that implements Azure ACS. I got the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.