Results 1 to 3 of 3
  1. #1
    Victors14 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default JTextField text not visible

    IDE: Eclipse Standard/SDK
    Version: Kepler Service Release 1

    JRE 7

    Im working on the Stanford online intro to programming class Assignment 6.
    http://see.stanford.edu/materials/ic...ame-surfer.pdf

    When I add the JTextField that allows you to input the name, the typed text is invisible. There is no cursor visible either. When I type text I can use getText to get what was typed, but I cannot see it on the screen. I have searched the forums for similar problems and haven't found anything.

    Java Code: (Incomplete, I only just started the project)

    Java Code:
    import acm.program.*;
    import acm.graphics.*;
    import acm.util.*;
    
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    import java.io.*;
    
    public class NameSurfer extends ConsoleProgram implements NameSurferConstants {
    
    	private JLabel label = new JLabel("Name ");
    	private JTextField nameField = new JTextField(20);
    	private JButton graph = new JButton("Graph");
    	private JButton clear = new JButton("Clear");
    	private String nameInput = "";
    	
    
    /**
     * This method has the responsibility for reading in the data base
     * and initializing the interactors at the bottom of the window.
     */
    	public void init() {
    		add(label, SOUTH);
    		add(nameField, SOUTH);
    		nameField.addActionListener(this);
    		nameField.setFont(Font.getFont(Font.SANS_SERIF));
    		add(graph, SOUTH);
    		add(clear, SOUTH);
    		addActionListeners();
    	}
    
    /* Method: actionPerformed(e) */
    /**
     * This class is responsible for detecting when the buttons are
     * clicked, so you will have to define a method to respond to
     * button actions.
     */
    	public void actionPerformed(ActionEvent e) {
    		if(e.getSource() == graph || e.getSource() == nameField) {
    			println("Graph: " + nameField.getText());
    		}
    		if(e.getSource() == clear) {
    			println("Clear");
    		}
    	}
    }

  2. #2
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: JTextField text not visible

    I'm pretty sure this is a bug in the acm library itself. I too had the same problem when I tried your code (even when simplified to just 1 JTextField) using an earlier copy of acm.jar downloaded from CS 1110: Assignment 5. I later found https://community.oracle.com/thread/...art=0&tstart=0 describing the same problem that you have.

    However the problem went away after I replaced acm.jar with the copy downloaded from Java Task Force Home Page.

  3. #3
    Victors14 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Disappearing Text within a JTextField
    By t338327 in forum New To Java
    Replies: 2
    Last Post: 09-18-2012, 03:07 AM
  2. Changing the text in a JTextField
    By mpankhurst in forum New To Java
    Replies: 5
    Last Post: 12-31-2011, 05:52 AM
  3. Reaplacing text in JTextField
    By PhQ in forum New To Java
    Replies: 5
    Last Post: 04-14-2010, 12:25 AM
  4. JTextField not visible?
    By McChill in forum New To Java
    Replies: 2
    Last Post: 05-20-2009, 12:17 AM
  5. Text are not visible in GUI
    By VinTiger in forum New To Java
    Replies: 5
    Last Post: 05-15-2009, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •