-1

I want to set access of a jpanel(which is in the JDesktopPane ) from JInternalFrame, I set it to public but no way its gives 'null' when I do some test like that:

JDesktop frameP = new JDesktop();
frameP.jPanel1.setVisible(true); //This is what I want but it doesn't work

System.out.println("Name " + frameP.jPanel1.getName());

so the last line gives me null that it means that he doesn't get the JPanel.

I try also that code:

 for(int k=0; k<frameP.getContentPane().getComponentCount();k++ ){
             if(frameP.getContentPane().getComponent(k)instanceof  JPanel){
                 JPanel pnl = (JPanel) frameP.getContentPane().getComponent(k);
                 if(pnl.getName().equals("jPanel1")){
                     pnl.setVisible(true);
                 }
                 System.out.println("Nom pnl: " +pnl.getName()); // That gives null too
             }
         } 

Any help please?

Majda
  • 99
  • 1
  • 3
  • 11
  • 1
    What is a JDesktop? Presumably this is your class, but you haven't provided the code for it, so any answers from us would just be guesses. – splungebob Mar 27 '13 at 16:08
  • Also, if you're trying to use JDesktopPanes, you don't add JPanels directly to them. You add your JPanels to a JInternalFrame, then add this JIF to the JDesktopPane, which is in turn added to a JFrame. – splungebob Mar 27 '13 at 16:11
  • JDesktop that's just the name of the JDesktopPane. I use the palette to add controls that's why but the panel is on JDesktop and I want to access it from the JInternalFrame – Majda Mar 27 '13 at 16:15
  • No, JDesktop is not "just the name of the JDesktopPane". Apparently you've subclassed it (not the same thing) and you haven't shown us the code for it. – splungebob Mar 27 '13 at 16:21
  • 1
    "I use the palette to add controls that's why but the panel is on JDesktop and I want to access it from the JInternalFrame"... Instead of trying to decipher this comment, I'll just point you to the tutorial: [How To Use Internal Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html) – splungebob Mar 27 '13 at 16:24
  • sorry I misunderstand you, JDesktop is the JFrame that contains the JInternalFrames it just contains the JMenuBar + JPanel and JDesktopPane . Which code should I show? – Majda Mar 27 '13 at 16:24

1 Answers1

0

I just resolve that problem I do that:

JDesktop.jpnlGauche.setVisible(false);
JDesktop.jpnlHaut.setVisible(false);
Majda
  • 99
  • 1
  • 3
  • 11