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

How to update/refresh JPanel on JButton click?  RSS feed

 
Ranjeet Kumar Singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to plot a graph and graph should display when JButton is clicked. To create data set, I am taking some value through JTextField and then created a chart and plotted it. I've got a problems: the chart doesn't refresh/update when I change the text field value.


 
Campbell Ritchie
Sheriff
Posts: 55284
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You appear to have landed in the wrong location. Never mind, I can move you somewhere more appropriate.
I presume you have tested that the actionPerformed method is actually being called? Put a print statement in it and you will get a printout: something like "Action Performed" would work nicely.
Why are you adding a new chart object? Why do you not have a method in the chart object which takes the new values and then repaints it?
Which layouts are you applying to what? Are you using BorderLayout.CENTER on a Component with a grid bag layout?
 
Steve Beckle
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your button logic seems sound....I ran the code w/o all the chart stuff to verify that "a" does change when I edit the text area and press the button. Have you inspected the dataset that's being created? I'd put in some print statements near the return of the method that creates the dataset to see exactly what's getting built into the chart data.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!