Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-17-2004, 06:57 AM   #1 (permalink)
Mkers12
Registered User
 
Join Date: Aug 2004
Posts: 3
Mkers12 is on a distinguished road
Question Adding infinite text fields

I'm writing a program that starts with 2 text fields. The user enters in an Id in the first field and name in the second field. Then he hits the add button. Once the add button is hit, I'd like 2 more empty text fields to appear below the ones that already have text in them to allow another entry and the process to be repeated.

Is it possible to do this and allow the user to add infinite text fields? Please let me know if I'm not being clear.

Thanks!
Mkers12 is offline   Reply With Quote
Old 08-17-2004, 08:19 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
are we talking web program or not?
__________________
Mike
sde is offline   Reply With Quote
Old 08-17-2004, 08:23 AM   #3 (permalink)
Mkers12
Registered User
 
Join Date: Aug 2004
Posts: 3
Mkers12 is on a distinguished road
nope, no web program
Mkers12 is offline   Reply With Quote
Old 08-17-2004, 08:41 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i'm no java gui programming expert, but maybe you can use the ArrayList object to create a dynamic array of text fields. in the onclick action of the button, just add 2 more text fields to the array list. ( or 1 button to each of the 2 array lists )

you may want to create a variable for y position of your buttons. you will modify this when the button is clicked too.

i don't have much experience with java gui programming, but this is how i'd do it in c#. sorry it's only theory, but i hope it helps.
__________________
Mike
sde is offline   Reply With Quote
Old 08-17-2004, 10:18 AM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I'm no good with GUI's, but yeah, you certainly should be able to do it. I'd start off by trying to add the text fields via the action of a button.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-17-2004, 10:46 AM   #6 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
You want to create an unlimited amount of text fields?! Why would the user sit there and fill in this infinate amount of text boxes?!

I think I see how you can do this easily. At least I do using vb6 again this is theory...

Create all the text fields you would possibly need then assign which ones to make 'invisible'.

When the add button is clicked, certain text boxes become visible again.

This is eaisly done in vb6 but I've never touched Java in my life. I only came in here out of both boredom and curiosity!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-17-2004, 11:08 AM   #7 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
That'd get you smacked by a proper coder. In Java, you can add these things on the fly. Just be sure to put it inside a ScrollPane or something, lest your window grow in size too much.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-17-2004, 11:15 AM   #8 (permalink)
Mkers12
Registered User
 
Join Date: Aug 2004
Posts: 3
Mkers12 is on a distinguished road
Correct me if I'm wrong here, but in order to declare a new text field I have to create a name for it right? And then add it to my frame (or Scroll Pane) like this:

private JFormattedTextField idText1 = new JFormattedTextField();

this.getContentPane().add(idText1, new XYConstraints(5, 5, 125, 25));

To do this dynamicly, would I use an array or arraryList (not too familar w/that) to store/create the name of the new text field?
Mkers12 is offline   Reply With Quote
Old 08-17-2004, 12:13 PM   #9 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I'm not sure exactly how Swing does it, but you should be able to simply add a new text field on the fly, without using an ArrayList. I honestly don't know.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MySQL] blob vs text redhead PHP 2 03-29-2004 11:15 PM


All times are GMT -8. The time now is 12:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting