Hello,
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);
dialog.setLocationRelativeTo(GraphGUIApp.getApplication().getMainFrame());
dialog.setVisible(true);
if (dialog.isConfirmed()) {
PaintPanel panel = new PaintPanel(width, height); // extends JPanel
PaintFrame internalFrame = new PaintFrame(title, panel);
try {
internalFrame.setSelected(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(GraphGUIView.class.getName()).log(Level.SEVERE, null, ex);
}
viewDesktopPane.add(internalFrame);
viewDesktopPane.setDragMode(javax.swing.JDesktopPane.OUTLINE_DRAG_MODE);
internalFrame.setVisible(true);
internalFrame.addFocusListener(new java.awt.event.FocusAdapter() {
@Override
public void focusGained(java.awt.event.FocusEvent e) {
System.out.println("focus");
}
@Override
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.