Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To read variable from child JPanel  RSS feed

 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I've made one JPanel and put 3 JPanels on it. I would like to read value from child (inner) JPanel and to print it on parent panel. The variable that contains that value is counter (that value is changeable) and parent panel is panel1, while the child panel is panel11.

I wrote this in panel1:


It only prints initial value of variable counter (I declared it as static int) and it doesn't change the value of variable.

Any ideas...?
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, it was a silly mistake. I forgot to put repaint() method in paintComponent.

Now it works just fine
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I forgot to put repaint() method in paintComponent.

No you should not put repaint() in the paintComonent() method. This will cause an infinite loop.
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where to put it then?
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you change the value of the variable you invoke repaint() on the parent panel.
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!