Jump to content

Change a JPanel from other class

- - - - -

  • Please log in to reply
3 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
How you can modify a JPanel where is in one class, from a different class? I have a JPanel and i want to setIcon() from other class.

Thank you

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
public class Gui extends JFrame{

  private JPanel;


  public void setPanelIcon(...){

    jPanel.setIcon(...);

  }

}

public class Other{

  public static void main(String[] args){

    Gui gui = new Gui();

    gui.setPanelIcon(...);

  }

}


#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
The class Other, should be main?

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
No, I just showed that the class containing the JPanel should get a method which allows other classes to use that method, and in the method the JPanel changes.
So even tho "Other" class doesn't know the Gui's JPanel, it can call a method of Gui, and Gui will do it itself.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users