I am developing a simple graph drawing application where each graph could be painted in internal frame.
I want to call a specified function whenever an internal frame got focus. I’ve tried to add “addFocusListener” to the internal frame but it didn’t work.
Multiple workspace (internal frame) can be created from file>New.
here is the newMenuIemAction

public void newGraph() {

        NewGraphDialog dialog = new NewGraphDialog(GraphGUIApp.getApplication().getMainFrame(), true);
        if (dialog.isConfirmed()) {
            PaintPanel panel = new PaintPanel(width, height); // extends JPanel

            PaintFrame internalFrame = new PaintFrame(title, panel);
            try {
            } catch (PropertyVetoException ex) {
                Logger.getLogger(GraphGUIView.class.getName()).log(Level.SEVERE, null, ex);


            internalFrame.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusGained(java.awt.event.FocusEvent e) {


                public void focusLost(java.awt.event.FocusEvent e) {


I' ve spent two days trying to figure out a solution, but I couldn't.
Any hint or help is very appreciated.

It works! thank you :)
Just one more question:
Which one do you think is better? using internal frames or tabbedPane?

Edited 6 Years Ago by H.Roger: n/a

It just depends on how the users will work with the separate panels. With tabs, all will be layered on the screen and only one can be active at any one time, whereas with the internal frames you can show as many or as few of the collection as you wish and they can be arranged in any manner you choose to view simultaneously.

This question has already been answered. Start a new discussion instead.