Hi Beni,
I found a problem with the focus mechanism.
When a dockable is closed it sometimes transfers the focus to its focus component.
The dockable and its focus component do not exist in Swing hierarchy anymore
so the result is that the application loses focus (you cannot use the Alt menu shortcuts anymore).
I have the following reproduction scenario:
- start Dock34
- click on the text area
- close the dockable (in the console you can see that JTextArea gets focus although it is gone already)
- press Alt - the menu does not react to the shortcut
package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.KeyboardFocusManager;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.CGridArea;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
public class Dock34
{
public static class FocusPropertyChangeListener implements PropertyChangeListener
{
public void propertyChange(PropertyChangeEvent e)
{
System.out.println("focus owner: " + e.getNewValue());
}
}
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception
{
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner",
new FocusPropertyChangeListener());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frame = new JFrame();
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("Menu");
menu.setMnemonic('m');
menubar.add(menu);
frame.setJMenuBar(menubar);
CControl control = new CControl(frame);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultSingleCDockable red = create(control, "Red", Color.RED);
CGrid grid = new CGrid(control);
grid.add(0, 0, 5, 3, red);
CGridArea area = control.createGridArea("aaa");
area.deploy(grid);
frame.getContentPane().add(area.getComponent(), BorderLayout.CENTER);
frame.setSize(new Dimension(600, 600));
frame.setVisible(true);
}
public static DefaultSingleCDockable create(CControl control, String title, Color color)
{
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(true);
panel.setBackground(color);
JTextArea textArea = new JTextArea("text");
JScrollPane sp = new JScrollPane(textArea);
panel.add(sp);
DefaultSingleCDockable dockable = new DefaultSingleCDockable(title, title, panel);
dockable.setCloseable(true);
dockable.setFocusComponent(textArea);
return dockable;
}
}
I can reproduce it both in 1.1.0 and 1.1.1p5a. I guess the problem is caused
by the delayed focus setting mechanism.
Would it be possible to fix it in both versions?
kind regards,
Maciej Modelski