So I am making this project where I need to insert into a JPanel container different types of Swing components (like a JButton, JTextArea etc). My main frame looks like this:
Basically I have a text are where a user inputs what he needs inserted (a Button for example) and the component appears in the JPanel. This is achieved dynamically using reflection. I have a method that looks like this:
enter code here
JComponent createComponent(String compName)
{
try {
Class<?> clazz=Class.forName("javax.swing.J"+compName);
JComponent jComponent=(JComponent) clazz.newInstance();
jComponent.setBounds(lastClick.x, lastClick.y, 100, 32);
snapPanel.add(jComponent);
mover.register(jComponent);
snapPanel.revalidate();
return jComponent;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
What I need done now is the following: after I click on a component I need for its properties to be displayed in the right hand side Jpanel, where I have created a JTable. And not only do I need the properties to be displayed, I need to be able to modify some of them, like the size.
I thought of using this library http://ift.tt/1j76zfs to import the componets properties into the table, but I have not been successful. What I think the logic should be is: after this step:
Class clazz=Class.forName("javax.swing.J"+compName);
I need to take clazz and reflect it into the Jtable somehow. I am new to this reflection api and don't know how to continue. I also don't have much experience constructing a default DefaultTableModel Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire