Access swing component on other tab of JTabbedPane

  • Thread starter Mike Bosschaert
  • Start date
M

Mike Bosschaert

Hi,
For my small application I want to use tabs. On one tab I display 'default
values' in JTextFields. On another tab I have a button which should do some
actions, based on the default values. I tried to write a method to collect
the desired default value, but I can't seem to find the right way. I see
why it does not work but I'm on the wrong track and can't see which way I
should go. The method I tried is given below.

Thanks for you help!

Mike



public static String getValueFromPanel(String panelName, String fieldName) {
String fieldValue="";
try {
Class cl = Class.forName("MyMusic");
Field[] f = cl.getFields();
for (int j = 0; j < f.length; j++) {
if (f[j].getType().toString().equals("class javax.swing.JPanel")) {
for (int i = 0; i < f[j].getComponentCount(); i++) {
if (f[j].getComponent(i).getName() == fieldName) {
fieldValue = f[j].getComponent(i).toString();
}
}
} else {
return "object: " + f[j].getType() + " not handled by method";
}
}
} catch (Exception ex){System.out.println(ex);};
return fieldValue;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top