Java等待游標顯示問題在應用程序中顯示等待游標時出現問題。每當鼠標位于定義自己游標的面板上方時,等待游標就不會出現。如果面板不更改游標,則會出現等待游標。我正在附上一個SSCE,以準確地解釋我的問題。public class BusyCursorTest extends javax.swing.JFrame {public BusyCursorTest() {
javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu menu = new javax.swing.JMenu("Menu");
javax.swing.JMenuItem wait1 = new javax.swing.JMenuItem("Wait 100 ms");
javax.swing.JMenuItem wait2 = new javax.swing.JMenuItem("Wait 250 ms");
javax.swing.JMenuItem wait3 = new javax.swing.JMenuItem("Wait 500 ms");
javax.swing.JMenuItem wait4 = new javax.swing.JMenuItem("Wait 1000 ms");
menu.add(wait1);
menu.add(wait2);
menu.add(wait3);
menu.add(wait4);
menuBar.add(menu);
setJMenuBar(menuBar);
wait1.addActionListener(getActionListener(this, delayActionListener(100)));
wait2.addActionListener(getActionListener(this, delayActionListener(250)));
wait3.addActionListener(getActionListener(this, delayActionListener(500)));
wait4.addActionListener(getActionListener(this, delayActionListener(1000)));
cursorPanel = new javax.swing.JPanel();
cursorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
});
public void actionPerformed(java.awt.event.ActionEvent ae) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
}
}
};
return actionListener;}private javax.swing.JPanel cursorPanel = null;public static java.awt.Cursor originalCursor = null;
public static final int DELAY_MS = 250;}運行附加的SSCE。當選擇第一個選項卡(“默認”)時,單擊1000 ms菜單項將顯示繁忙的光標。當選擇第二個選項卡(“游標更改”)時,單擊1000 ms菜單項不會顯示繁忙的游標。我該如何解決這個問題?我強烈希望我的代碼不需要考慮到任何一個面板,因為這對我來說是非常困難的,因為我很難跟蹤哪些面板可能處于最前沿。此外,由于鼠標單擊,事件并不總是生成。建議的解決方法是什么,以便我可以在頂級容器中修改行為?
添加回答
舉報
0/150
提交
取消