Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

JButton and JTextField questions

Thread view: 
Gil - 24 Feb 2005 13:12 GMT
I have a JTabbedPane with 4 Panes.  Each Pane has several panels.
Each panel has several JTextFields.  On the last Pane in the bottom
panel, I have a JButton that basically starts a process for the GUI
client.

When the user presses this button, I need to determine whether any of
the JTextFields were filled out in any of the Panes and if any of them
were, then I need to get the text in these fields.

The problem I have is that each Panel is a class of it's own so the
actionPerformed method of my JButton doesn't have access to the
JTextFields in all of the Panels.  How can I solve this?  Does anyone
have any ideas?

Thank you,

Gil
Chris Smith - 24 Feb 2005 13:44 GMT
> I have a JTabbedPane with 4 Panes.  Each Pane has several panels.
> Each panel has several JTextFields.  On the last Pane in the bottom
[quoted text clipped - 9 lines]
> JTextFields in all of the Panels.  How can I solve this?  Does anyone
> have any ideas?

You just need to communicate the right information to the right places.  
The right way to do this depends very much on the abstraction involved.  
There are several possibilities, and these are the ones that come to
mind immediately.

1. If these panes are really so connected, then perhaps you should build
them all in the same place, instead of writing a separate class for
each.

2. You could have each pane share the text field models (Document
instances) for each of the text fields.  The panes with text fields
would store those Document instances in the shared location as the
fields are created, and the final pane would read from those Document
instances.  A variation is to store JTextField instances instead of
models.

3. You could have each pane of the JTabbedPane register a ChangeListener
on the JTabbedPane itself, and when it loses selection have it be
responsible for filling in some kind of higher-level model object with
the data from the pane.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Gil - 28 Feb 2005 13:49 GMT
Hi Chris,

Thanks for your reply!

> 2. You could have each pane share the text field models (Document
> instances) for each of the text fields.  The panes with text fields
> would store those Document instances in the shared location as the
> fields are created, and the final pane would read from those Document
> instances.  A variation is to store JTextField instances instead of
> models.

Could you give an example of how this might be done?  I don't think I
understand what you mean by text field models.

Thank you,

Gil
Dirk Starke - 01 Mar 2005 08:22 GMT
Hello Gil,

if you need the text of all textfields and the order of the textfields
does not matter then you might just walk through the component tree:
- Get all children of any pane with getComponents(),
- make a for loop and look for children of type JTextField,
- also search for textfields in child-panes, that's it.
You can do the job recursive.

If the order of the textfields matters or those textfields do have any
other necessary property you need when processing the text then you
might design a panel---say MyExtraPanel---containing just one
textfield. MyExtraPanel could have an attribute 'xyz' and a getter for
that. You could get all MyExtraPanels the same way you get all
JTextFields and call getXyz().

Greeting
   Dirk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.