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.

Ok, just found that the focus listener works if you add


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

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.

I'll stick to internal frames.
Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.