我正在用簡單的GUI構建簡單的聊天應用程序,但是我有一個問題,將Enter鍵指定給發送按鈕。現在按Alt + Enter是非常不切實際的。添加Enter鍵作爲JButton加速器
public void buildInterface() {
//some other components
btnSend = new JButton("Send");
btnExit = new JButton("Exit");
btnSearch=new JButton("Search");
btnSend.setMnemonic(KeyEvent.VK_ENTER);
JPanel box=new JPanel();
add(box, BorderLayout.SOUTH);
box.add(tfInput);
box.add(btnSend);
box.add(btnExit);
box.add(btnSearch);
}