Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble with revalidate() and repaint()

 
Nate Rogers
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on an applet the past couple of days that basically acts as a very specialized calculator. I've written other applets that use the same method that I'm using here, but for some reason I can't seem to get a couple of the panels to revalidate() and repaint(). Here is the section of code I'm working on:



I have all of those println() as I'm trying to debug. I've checked the TestSim objects and they're being stored in the ArrayList active properly. Additionally, I can retrieve all of the information properly. I've identified the updatePlot() method as the problem:



I've used this method many times before and was able to add and repaint the plot just fine. However, it doesn't seem to be working this time. I've been at it all day, and I'm hoping some fresh eyes may catch something simple that I've missed.

Also, in case you're unfamiliar with jmathplot, here is the project site: https://code.google.com/p/jmathplot/
It has all of the source code and documentation. It's a really nice little package, and if I wasn't so busy with my current work, I would join to add a few features.

Thanks for taking a look!
 
Nate Rogers
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on it a bit more. Here's the console output if I click on the "Generate" button.

generate
Axial Test
Axial-1
active.size() = 1
TestSim@8c0d58
Axial-1
1: Axial-1
2: java.awt.Color[r=0,g=0,b=255]
3: 0.001
4: 0.0053
0
Setting Axis Labels...
org.math.plot.Plot2DPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
org.math.plot.Plot2DPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
org.math.plot.Plot2DPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
org.math.plot.Plot2DPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
org.math.plot.Plot2DPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]


Note how the Plot2DPanel remains invalid even after I call revalidate(). To save you some time going through the documentation, this toString() method is inherited from JPanel. Thoughts?
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
To help us help you, please provide your SSCCE (<= click link to find out what it really means) code.
 
Nate Rogers
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind. I was able to figure it out. Today, as I was combing through my code trying to figure out what I could take out to make it easier to read (for all of you), I noticed that on line 311:



I add the plot panel instead of its container (plotContainer). Changing this solved my problem. However, I did notice that the string output hasn't changed at all. It's not important, but food for thought.

Thanks anyway!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic