0

I have a JFrame which has many LayredPane's and those LayerdPane's has many JPanel's in it.

i have more than 50 JPanel's in the a Single Layered Pane where i want to switch the panels according to my JCombobox selected index.

so i have copied all the Panel Variable names as String Array and pass the Panel Variable name as per the JCombobox index number name.

Object Array with Panel Variable Names

public Object panelNames[]={
    "clinicalPathalogyReport",
    "clinicalHaematologyReport",
    "clinicalSerologyReport",
    "clinicalSerologyReport",
    "clinicalSerologyReport",
    "clinicalSerologyReport",
    "clinicalBiochemistryReport",
    "clinicalHaemotologyReport",
    "clinicalBiochemistryReport1",
    "clinicalBiochemistryReport2",
    "clinicalBiochemistryReport3",
    "clinicalHaemotologyReport2",
    "urinePregnancyTest",
    "completeBloodPicture",
    "clinicalPathalogyReport1",
    "clinicalBiochemistryReport4",
    "clinicalBiochemistryReport5"};

So i want to pass the Variable name with my Selected index

so here is my source code to perform action

int i=uniqueTests.getSelectedIndex();

                ltlayeredPane.removeAll();
                ltlayeredPane.add((Component)panelNames[i]);
                ltlayeredPane.repaint();
                ltlayeredPane.revalidate();

But i am having Class Cast Exception

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Intact Abode
  • 382
  • 5
  • 20

0 Answers0