It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Using JTextfields in a JTabbedPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using JTextfields in a JTabbedPane" Watch "Using JTextfields in a JTabbedPane" New topic
Author

Using JTextfields in a JTabbedPane

Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Hi

I created a GUI application, that uses JTabbedPane.
Inside the Tabs, I am using JTextfields to display data from an Arraylist.

I am having problems sending data from my arraylist to the textfields in my gui.

I try to access the tab selected similar to accessing a arraylist.

However this does not seem as straight forward as I think..

Could someone provide some insight ???

Thanks

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

What do you have so far?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Hi Rob

I have the following code below.

I am pulling data from the arraylist eloc, and trying to place the data in textfields in the JTabbedPane's txtTotalWater box..


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

How about you use arrays of text fields, with the indexes being equal to the tab indexes? Or List<JTextField>? You can then use the tab index to directly retrieve the text fields.

Also, another oddity:
That's a lot of code repretition. In fact, the colors are the only real difference. So why not move the other two lines out of the switch statement?
You could also move the entire color code out of the if-statement if you use two arrays:
In fact, you could turn those two arrays into private static final fields.
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Rob,

Thanks for the advice, I followed your advice and streamlined the method.

Works great..

How do I now access a Textfield in a panel of a JTabbedPane so I can add or remove String information ?

I have tried typing in "jtp.setSelectedIndex(tabindex);", trying to see if I can access it similar to a Arraylist.
But the IDE does not let me.

Thanks

 
 
subject: Using JTextfields in a JTabbedPane
 
Similar Threads
Adding JTextField to a JPanel at runtime
reading text file into GUI
refreshing the jtabbedpane
JComponents not work at client PC
how to update fields when a table cell is edited.