If I have a JPanel
object that I can't modify, is there a way I can modify the paintComponent
method of it without using injection?
One approach I was thinking of was getting the JPanel
's Graphics
object, passing it to paintComponent()
, performing operations on this Graphics
object, and finally painting that in my custom JPanel
. The problem with this, is I need to be able to do this every time the original JPanel
's paintComponent()
is called.
I don't need to replace what's in paintComponent(), I just need to add on to it.
For example:
JFrame frame = null;
for (Frame f : JFrame.getFrames()) {
if (((JFrame) f).getTitle().equals("Title")) {
JPanel panel = null;
// ... Cycle through all components and get the one that's a JPanel
// I want to use ColorConvertOp to make panel greyscale
}
}