javax.swing Class JComponentgrabFocus public void grabFocus() Sets the focus on the receiving component if it doesn't already have it. This method is for focus managers. You rarely want to call this method; use requestFocus() instead.requestFocus public void requestFocus()Sets focus on the receiving component if isRequestFocusEnabled returns true and the component doesn't already have focus. Overrides: requestFocus in class Component Following copied from class: java.awt.Component
public void actionPerformed(ActionEvent e){
jbutton2.requestFocus();
}
}
我试过了
JButton.grabFocus();
jbutton2.requestFocus();
两者都可行
可是有什么区别吗?
Class JComponentgrabFocus
public void grabFocus()
Sets the focus on the receiving component if it doesn't already have it. This method is for focus managers. You rarely want to call this method; use requestFocus() instead.requestFocus
public void requestFocus()Sets focus on the receiving component if isRequestFocusEnabled returns true and the component doesn't already have focus.
Overrides:
requestFocus in class Component
Following copied from class: java.awt.Component
requestFocus();
比较好