SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 8th, 2008, 09:08 PM
JMV290 JMV290 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 9 JMV290 User rank is Private First Class (20 - 50 Reputation Level)JMV290 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 27 m 19 sec
Reputation Power: 0
Homework - Help with formatting a TextField.

This is part of the code of a program we are working on in our Java class. The assignment is done but a classmate and I are just trying to work on one final graphical issue that results when the user enters a valid "Social Security Number"(just a 9 digit number) after previously entering an invalid one.

Code:
   // private inner class for event handling
    private class TextFieldHandler implements ActionListener
    {
        // process textfield events
        public void actionPerformed ( ActionEvent event )
        
        {
            String socialInput = socialTextField.getText (); // declare string to display
            socialTextField.selectAll ();
            socialTextField.requestFocus ();
            socialTextField.setText ( "" );             
            socialLabelPrompt.setText ( "Please enter a Social Security Number" );             
            
            try
            {
                arrayStorage.validateSSN (socialInput);
                arrayStorage.addSocial (socialInput);
                System.out.printf ( "\n%8s", "Social Security Number: " );
                System.out.println (socialInput);
            }
            
            catch (InputMismatchException e)
            {
                socialLabelPrompt.setText ( e.getMessage () + ".  " + "Please reenter Social Security Number" );
                socialTextField.setText ( "SOCIAL SECURITY NUMBER" );
                socialTextField.selectAll ();
                socialTextField.requestFocus ();
                socialLabelPrompt.setHorizontalTextPosition ( SwingConstants.CENTER );
                socialLabelPrompt.setVerticalTextPosition ( SwingConstants.BOTTOM );                
            }
            
            catch (DuplicateName duplicateSocialError)
            {    
                
            }                  
            
        }
        
    }



More specifically the area of code, I believe, is:

Code:
            String socialInput = socialTextField.getText (); // declare string to display
            socialTextField.selectAll ();
            socialTextField.requestFocus ();
            socialTextField.setText ( "" );             
            socialLabelPrompt.setText ( "Please enter a Social Security Number" );      



socialTextField.setText( "" ); is the line in question. Is there a way to make that always wide enough for 9 characters?

Putting \t in the quotes puts a tab, but the user needs to backspace to remove the tab; this is not desirable. Is there any modification I can make that would allow me to keep the field empty and still have it at a specific width?

Thanks.

Reply With Quote
  #2  
Old May 9th, 2008, 03:15 PM
Dijkstra Dijkstra is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Location: UK
Posts: 71 Dijkstra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 17 h 32 m 13 sec
Reputation Power: 1
Have you looked at the API for the TextField class? Did you try any particular methods in order to set the width? Worth a look if you haven't done so already.

Reply With Quote
  #3  
Old May 9th, 2008, 08:47 PM
JMV290 JMV290 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 9 JMV290 User rank is Private First Class (20 - 50 Reputation Level)JMV290 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 27 m 19 sec
Reputation Power: 0
Quote:
Originally Posted by Dijkstra
Have you looked at the API for the TextField class? Did you try any particular methods in order to set the width? Worth a look if you haven't done so already.
Thanks. Setting the width to 15 worked perfectly.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Help with formatting a TextField.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway