A
Ashraf Fouad
Dears,
I have JComponent object I want to get all its internal components
and their member variable names. i.e.:
Lets consider
import javax.swing.*;
import java.awt.GridLayout;
public class MainWindow
extends JDialog
{
private GridLayout gridLayout1 = new GridLayout();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
public MainWindow()
{
this.getContentPane().setLayout(gridLayout1);
gridLayout1.setColumns(2);
gridLayout1.setRows(2);
jLabel1.setText("jLabel1");
jLabel2.setText("jLabel2");
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jTextField1, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jTextField2, null);
this.show();
}
public static void main(String[] args)
{
MainWindow mainWindow = new MainWindow();
}
}
All I want is 2 Arrays:
========================
- one holding member field names (String) l_Names containing [
"jLabel1", "jLabel2", "jTextField1", "jTextField2" ]
- second holding internal components (Objects) l_Components containing
[ ref to jLabel1, ref to jLabel2, ref to jTextField1,
ref to jTextField2 ]
I can get the first Vector by:
String[] l_Names = new String();
Field[] l_Fields = MainWindow.getClass().getDeclaredFields();
for ( int i = 0; i < l_Fields.length; i++)
{
l_Names = l_Fields.getName();
}
The second I can get by:
Component[] l_Components = MainWindow.getComponents();
The problem is that I can't gaurantee that the order of the two tables
are the same ??
Does anyone have a solution or another approach ??
Thankx
I have JComponent object I want to get all its internal components
and their member variable names. i.e.:
Lets consider
import javax.swing.*;
import java.awt.GridLayout;
public class MainWindow
extends JDialog
{
private GridLayout gridLayout1 = new GridLayout();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
public MainWindow()
{
this.getContentPane().setLayout(gridLayout1);
gridLayout1.setColumns(2);
gridLayout1.setRows(2);
jLabel1.setText("jLabel1");
jLabel2.setText("jLabel2");
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jTextField1, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jTextField2, null);
this.show();
}
public static void main(String[] args)
{
MainWindow mainWindow = new MainWindow();
}
}
All I want is 2 Arrays:
========================
- one holding member field names (String) l_Names containing [
"jLabel1", "jLabel2", "jTextField1", "jTextField2" ]
- second holding internal components (Objects) l_Components containing
[ ref to jLabel1, ref to jLabel2, ref to jTextField1,
ref to jTextField2 ]
I can get the first Vector by:
String[] l_Names = new String();
Field[] l_Fields = MainWindow.getClass().getDeclaredFields();
for ( int i = 0; i < l_Fields.length; i++)
{
l_Names = l_Fields.getName();
}
The second I can get by:
Component[] l_Components = MainWindow.getComponents();
The problem is that I can't gaurantee that the order of the two tables
are the same ??
Does anyone have a solution or another approach ??
Thankx