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

  • SEARCH
  • Home
  • 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 8664339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:13:05+00:00 2026-06-12T17:13:05+00:00

My goal is to write something that is visible to the user in the

  • 0

My goal is to write something that is visible to the user in the JTextField and to display this text in the console.
As of now, the JTextField is accepting text but nothing shows. No cursor, no text.

I’ve tried using textfield.setEditable(true), textfield.setEnable(true) and different fore and background colors but nothing happens.

Curiously I can use textField.setText(“Random text”) and it shows, but I cant delete it or edit this when the program is running and it’s not included in the outputs from getText().

This is the program :

import acm.program.*;

import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class TextFieldTest extends ConsoleProgram implements SomeConstants {

public void init() {
    setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);

    textField = new JTextField(20);
    add(textField, SOUTH);
    textField.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == textField)
        println("Hi, " + textField.getText());
}

private JTextField textField;
}
  • 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-12T17:13:06+00:00Added an answer on June 12, 2026 at 5:13 pm

    If you’re working with acm.program.ConsoleProgram, you may need to use Java SE 5 (version 1.5), as suggested here.

    Addendum: As @Tor comments, java.awt.TextField may be acceptable under later versions of the JRE.

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

Sidebar

Related Questions

Goal is to make a dialog that appears on menu_key pressed, but it keeps
This is not a homework question, just something at work that's bugging me. I'm
I'm trying to do something that I think should be fairly simple but I've
I'm trying to build an object that looks something like this: public class MyObject
I have a DB like this that I generated from EF: Now I'd like
My goal is to write some sort of chatterbot that speaks in spanish. I've
So basically I want to write a function that can be written like this:
I saw this demo once that printed out a paragraph of text (like you'd
I have a flat file that is pipe delimited and looks something like this
My final goal is to write the program which can run on the Unix

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.