Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

multi swing component

  Asked By: Mada    Date: Apr 04    Category: Java    Views: 1070
  

i have problem to use multiple component like label , textbux , button
, .. in my form . can someone tell me how can i use index in name of
component for changing its property in loop
, tanx for your consideration

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Calvin Banks     Answered On: Apr 04

use one of the following methods:

1) use an string with an index  for your component  names (like label1 , label2, label3) and then use introspection.

2) put your components in an collection (for example an Array) then iterate over collection content and do what ever you want with them

3) use your parent component (form, dialog) getChildren to get collection of components, and then iterate over them

 
Answer #2    Answered By: Ralph Murray     Answered On: Apr 04

You can use Layouts to have and arrange your components like labels and textfield and so.
if you want indexing on your components, you can dynamicaly generate your components
when loading your application or in handling an event on some of your components, like changing  state of a comboBox, if you dynamicaly change your form  components( add some components or remove them ) or change the arrangement of comopnents, you shoud call the revalidate method on your component( perhaps a JFrame or JPanel ) to apply this changes.

 
Answer #3    Answered By: Arnelle Schmidt     Answered On: Apr 04

It's easy, just create an array of components:

JBotton[] buttons = new JButton[10];
for( int i = 0 ; i < 10 ; i++ ) {
buttons[i] = new JButton("Button " + i);
}

 
Answer #4    Answered By: Cleopatra Massri     Answered On: Apr 04

May i see the code written by you???

 
Didn't find what you were looking for? Find more on multi swing component Or get search suggestion and latest updates.




Tagged: