I have been working on trying to transfer focus and have not been successful. What I'd like is to recreate how menus work. For instance I want a user to mouseDown on a button and have a frame displayed receive focus to capture mouseMoved events without having to release.

Any ideas? I'll paste some code. Thanks.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Main {
private static JPopupMenu pop ;
private static JList list;

public static void main(String[] args) {

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(300, 300));
JButton b = new JButton("Test");
pop = new JPopupMenu();
JScrollPane j = new JScrollPane();
j.setPreferredSize(new Dimension(300, 300));
String[] data = {"one", "two", "three", "four","five", "six", "seven"};
list = new JList(data);

list.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
list.setSelectedIndex(list.locationToIndex(e.getPo int()));
}
});


j.setViewportView(list);

pop.add(j);


panel.add(b);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);

b.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Component c = (Component) e.getSource();
if(!pop.isVisible()) {
pop.show(c, c.getX(), c.getY());
//KeyboardFocusManager.getCurrentKeyboardFocusManage r().clearGlobalFocusOwner();
list.requestFocusInWindow(); //This doesn't work
}
}
});
}
}