I have a tabbed pane that has three panels on it. I am using these panels to plot some data. At first I wanted to place a "plot" button on this tabbed pane to invoke the plotting method but I didn't like the look of it.
So, now I was hoping to detect when my tabbed pane received focus and call a paint() method that would do the plotting.
The class that creates the three panels extends ComponentUI and I have a "public void paint (Graphics g, JComponent j)" method in this class.
However, it never gets called.
Anyone have any ideas what I could be missing here?
I am not sure what your problem is with the way you have things setup. But I'd like to offer a suggestion...
Extends JPanel for your 3 panels and override the paintComponent(Graphics g) method for your painting. What should happen is when you switch tabs the paintComponent method should be called automagically, thereby drawing your plots.
This has created another, although much less daunting, problem.
The original three panels created in the constructor are no longer showing up.
It's not a big deal, because I will be doing all the actual work in my paint method anyway. I was just wondering why they wouldn't show up. It probably has something to do with my overridding the paint method.
So, in my constructor method "this" is referring to the panel. It's not needed, I know. It's there because the code is in a state of flux and at one point it was needed.
Here my constructor at the moment:
And here is my Paint() method.
Notice my comment. It was the only way I know to get my original three panels (from the contructo method) painted.
Intrestingly, I have also overridden the Paint( Graphics JComponent c) method (just for testing purposes) like this:
However, I have never seen this method invoked, and it still exists in my code at the moment.
Also, I am beginning to see another problem that you may be able to give me a hand with. If I have a lot of data to plot, I thought that I would simply resize my panels, plot my data on them, and use the scrollbars to view the plot.
I can't seem to get the scrollbars to appear. I have tried panel1.setSize() in my paint method but this did not cause the scrolls bars to appear.
I have to say that I am a bit confused as to what you are wanting to do now. I haven't run across a situation where I need to put 3 JPanels on a JPanel that I am overriding paint. But at any rate, here are my thoughts:
1. Override paintComponent(Graphics g), not paint(Graphics g). I don't remember why, I just know that this is the rule. It has something to do with when and how it gets called, you don't want to change when paint gets called. paintComponent will issue the command for you.
2. In paintComponent the first line should be super.paintComponent(g). This is not a hack. This is to clear the drawing area everytime before you draw on the area.
Here is the code I used and I can see all 3 JPanels on my custom panel (which still confuses me as to why you are doing this. )
Joined: Sep 29, 2004
thanks for the help.
I'll modify my paint method, but not until tomorrow.
It's too close to miller time to do anything else today.
Anyway, my application is monitoring three servers that we are using on our network. This part of the application will show simple line graphs of the response times of the those three servers.
Basically, my requirement is that I need to show the three line graphs at the same time. I suppose it could be drawn on one panel.
Originally posted by jefff willis: I suppose it could be drawn on one panel.
No no no. What you need is a custom JPanel that you override the paintComponent method in and then place 3 of those on the Container (JFrame, JPanel, Window, whatever).
The way you were doing it is putting 3 JPanels on 1 custom JPanel. It should be the other way around. That's what was confusing me about your app. I assumed you wanted it the way you described. But the way you were coding, it didn't make sense.
Joined: Sep 29, 2004
OK, check out this complete class:
There are a few issues here.
1. this class's paintComponent is never called. 2. this panel is sufficiently large at creation time to display about three hours of "server monitor" data. However if this application were to monitor, say twenty four hours of "server monitor" data, then I planned on simply calling this.reshape() inside the paint() method to give me the necessary space to draw my graph. However, doing this does not cause my scrollbars to appear. It does resize my panel, but that is not what I need.