2

I'm doing a program like Gimp and i have a JInternalFrame for change the color of shapes and i paint the shapes in other JInternalFrame so i have to get my frame to get the JInternalFrame where i want to paint. I don't know how to get the parent of the colors JInternalFrame to change the color in the JInternalFrame where I'll paint.

Jonas
  • 121,568
  • 97
  • 310
  • 388
mike02
  • 21
  • 1
  • 2

2 Answers2

2

Look at SwingUtilities.getAncestorOfClass(Class c, Component comp). For example:

You can use SwingUtilities.getAncestorOfClass(JFrame.class,compinstance)

lujop
  • 13,504
  • 9
  • 62
  • 95
1

What ever is doing the painting needs a reference to the selected color. I would suggest not directly referencing one frame to another but instead have a central variable that holds the selected color that can then be used by whatever tool needs it. Once the use "paints" on the screen you will need to store what the paint in some format so that your Java code can continue to repaint it.

jzd
  • 23,473
  • 9
  • 54
  • 76