本文整理汇总了Java中java.awt.Component.requestFocus方法的典型用法代码示例。如果您正苦于以下问题:Java Component.requestFocus方法的具体用法?Java Component.requestFocus怎么用?Java Component.requestFocus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.requestFocus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestFocus
import java.awt.Component; //导入方法依赖的package包/类
private void requestFocus(JComponent comp) {
Container container = SwingUtilities.getAncestorOfClass(TopComponent.class, comp);
if (container != null) {
((TopComponent)container).requestActive();
}
else {
Component f = comp;
do {
f = f.getParent();
if (f instanceof Frame) {
break;
}
} while (f != null);
if (f != null) {
f.requestFocus();
}
comp.requestFocus();
}
}
示例2: actionPerformed
import java.awt.Component; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
int selIndexBefore = getSelectedIndex();
defaultAction.actionPerformed( e );
int selIndexCurrent = getSelectedIndex();
if( selIndexBefore != selIndexCurrent )
return;
if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() )
return;
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Container container = kfm.getCurrentFocusCycleRoot();
FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
if( null == policy )
policy = kfm.getDefaultFocusTraversalPolicy();
Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this )
: policy.getComponentBefore( container, CategoryList.this );
if( null != next && next instanceof CategoryButton ) {
clearSelection();
next.requestFocus();
}
}
示例3: focusSpinnerIfNecessary
import java.awt.Component; //导入方法依赖的package包/类
/**
* Requests focus on a child of the spinner if the spinner doesn't have
* focus.
*/
private void focusSpinnerIfNecessary()
{
Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if( spinner.isRequestFocusEnabled() && (fo == null || !SwingUtilities.isDescendingFrom(fo, spinner)) )
{
Container root = spinner;
if( !root.isFocusCycleRoot() )
{
root = root.getFocusCycleRootAncestor();
}
if( root != null )
{
FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
Component child = ftp.getComponentAfter(root, spinner);
if( child != null && SwingUtilities.isDescendingFrom(child, spinner) )
{
child.requestFocus();
}
}
}
}
示例4: doRelease
import java.awt.Component; //导入方法依赖的package包/类
private void doRelease(JLabel label) {
Component labelFor = label.getLabelFor();
if (labelFor != null && labelFor.isEnabled()) {
InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
if (inputMap != null) {
// inputMap should never be null.
int dka = label.getDisplayedMnemonic();
inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
}
if (labelFor instanceof Container &&
((Container) labelFor).isFocusCycleRoot()) {
labelFor.requestFocus();
} else {
SwingUtilities2.compositeRequestFocus(labelFor);
}
}
}
示例5: requestFocus
import java.awt.Component; //导入方法依赖的package包/类
@Override
public void requestFocus() {
super.requestFocus();
Component comp = getRefactoringPanelComp();
if(comp != null) {
comp.requestFocus();
}
}
示例6: actionPerformed
import java.awt.Component; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
setFocusCycleRoot(false);
try {
Container con = BaseTable.this.getFocusCycleRootAncestor();
if (con != null) {
Component target = BaseTable.this;
if (getParent() instanceof JViewport) {
target = getParent().getParent();
if (target == con) {
target = BaseTable.this;
}
}
EventObject eo = EventQueue.getCurrentEvent();
boolean backward = false;
if (eo instanceof KeyEvent) {
backward = ((((KeyEvent) eo).getModifiers() & KeyEvent.SHIFT_MASK) != 0) &&
((((KeyEvent) eo).getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0);
}
Component to = backward ? con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this)
: con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this);
if (to == BaseTable.this) {
to = backward ? con.getFocusTraversalPolicy().getFirstComponent(con)
: con.getFocusTraversalPolicy().getLastComponent(con);
}
to.requestFocus();
}
} finally {
setFocusCycleRoot(true);
}
}
示例7: processKeyEvent
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void processKeyEvent(KeyEvent e) {
if (!isEditing())
super.processKeyEvent(e);
else {
Component component = ((DefaultCellEditor) getCellEditor(lastRow, lastColumn)).getComponent();
component.requestFocus();
component.dispatchEvent(new KeyEvent(component, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar()));
}
}
示例8: requestFocusForMessage
import java.awt.Component; //导入方法依赖的package包/类
/** Requests focus for <code>currentMessage</code> component.
* If it is of <code>JComponent</code> type it tries default focus
* request first. */
private void requestFocusForMessage() {
Component comp = currentMessage;
if(comp == null) {
return;
}
if (/*!Constants.AUTO_FOCUS &&*/ FocusManager.getCurrentManager().getActiveWindow() == null) {
// Do not steal focus if no Java window have it
Component defComp = null;
Container nearestRoot =
(comp instanceof Container && ((Container) comp).isFocusCycleRoot()) ? (Container) comp : comp.getFocusCycleRootAncestor();
if (nearestRoot != null) {
defComp = nearestRoot.getFocusTraversalPolicy().getDefaultComponent(nearestRoot);
}
if (defComp != null) {
defComp.requestFocusInWindow();
} else {
comp.requestFocusInWindow();
}
} else {
if (!(comp instanceof JComponent)
|| !((JComponent)comp).requestDefaultFocus()) {
comp.requestFocus();
}
}
}
示例9: componentActivated
import java.awt.Component; //导入方法依赖的package包/类
protected void componentActivated() {
super.componentActivated();
if (lastFocusOwner != null) {
lastFocusOwner.requestFocus();
} else {
Component defaultFocusOwner = defaultFocusOwner();
if (defaultFocusOwner != null) defaultFocusOwner.requestFocus();
}
KeyboardFocusManager.getCurrentKeyboardFocusManager().
addPropertyChangeListener("focusOwner", focusListener); // NOI18N
}
示例10: valueChanged
import java.awt.Component; //导入方法依赖的package包/类
public void valueChanged(ListSelectionEvent e) {
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
Component editor = table.getEditorComponent();
if (editor != null) {
editor.requestFocus();
}
if (editor instanceof JTextComponent) {
JTextComponent textComp = (JTextComponent) editor;
textComp.selectAll();
}
}
示例11: valueChanged
import java.awt.Component; //导入方法依赖的package包/类
public void valueChanged(ListSelectionEvent e) {
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
Component editor = table.getEditorComponent();
if (editor instanceof JComboBox) {
editor = ((JComboBox) editor).getEditor().getEditorComponent();
}
if (editor != null) {
editor.requestFocus();
}
if (editor instanceof JTextComponent) {
JTextComponent textComp = (JTextComponent) editor;
textComp.selectAll();
}
}
示例12: requestFocus
import java.awt.Component; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void requestFocus() {
if (this.pane != null
&& this.pane.getUI() instanceof FreeColOptionPaneUI) {
Component c = ((FreeColOptionPaneUI)this.pane.getUI())
.getInitialFocusComponent();
if (c != null) {
c.requestFocus();
}
}
}
示例13: ShowMessageConfirm
import java.awt.Component; //导入方法依赖的package包/类
public static int ShowMessageConfirm(Component parente, String msgTexto, boolean msgConfirm) {
if (msgConfirm) {
return ShowMessageConfirm(parente, msgTexto);
}
if (parente != null) parente.requestFocus();
return (JOptionPane.showConfirmDialog(parente, (msgTexto.isEmpty() ? "?" : " " + msgTexto),
Editor.fromConfiguracao.getValor("Controler.MSG_CONFIRM_TITLE"),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE));
}
示例14: actionPerformed
import java.awt.Component; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
setFocusCycleRoot(false);
try {
Container con = ETable.this.getFocusCycleRootAncestor();
if (con != null) {
/*
Component target = ETable.this;
if (getParent() instanceof JViewport) {
target = getParent().getParent();
if (target == con) {
target = ETable.this;
}
}
*/
EventObject eo = EventQueue.getCurrentEvent();
boolean backward = false;
if (eo instanceof KeyEvent) {
backward =
(((KeyEvent) eo).getModifiers()
& KeyEvent.SHIFT_MASK)
!= 0 && (((KeyEvent) eo).getModifiersEx() &
KeyEvent.SHIFT_DOWN_MASK) != 0;
}
Component c = ETable.this;
Component to;
Container parentWithFTP = null;
do {
FocusTraversalPolicy ftp = con.getFocusTraversalPolicy();
to = backward ? ftp.getComponentBefore(con, c)
: ftp.getComponentAfter(con, c);
if (to == ETable.this) {
to = backward ? ftp.getFirstComponent(con)
: ftp.getLastComponent(con);
}
if (to == ETable.this) {
parentWithFTP = con.getParent();
if (parentWithFTP != null) {
parentWithFTP = parentWithFTP.getFocusCycleRootAncestor();
}
if (parentWithFTP != null) {
c = con;
con = parentWithFTP;
}
}
} while (to == ETable.this && parentWithFTP != null);
if (to != null) {
to.requestFocus();
}
}
} finally {
setFocusCycleRoot(true);
}
}
示例15: propertyChange
import java.awt.Component; //导入方法依赖的package包/类
public void propertyChange(final java.beans.PropertyChangeEvent evt) {
if( !SwingUtilities.isEventDispatchThread() ) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
propertyChange(evt);
}
});
return;
}
boolean update = false;
if (DialogDescriptor.PROP_OPTIONS.equals(evt.getPropertyName())) {
initializeButtons();
update = true;
} else if (DialogDescriptor.PROP_OPTION_TYPE.equals(evt.getPropertyName())) {
initializeButtons();
update = true;
} else if (DialogDescriptor.PROP_OPTIONS_ALIGN.equals(evt.getPropertyName())) {
initializeButtons();
update = true;
} else if (DialogDescriptor.PROP_MESSAGE.equals(evt.getPropertyName())) {
initializeMessage();
requestFocusForMessage();
// In case change of help ID on component message:
updateHelp();
update = true;
} else if (DialogDescriptor.PROP_MESSAGE_TYPE.equals(evt.getPropertyName())) {
initializeMessage();
requestFocusForMessage();
update = true;
} else if (DialogDescriptor.PROP_TITLE.equals(evt.getPropertyName())) {
setTitle(descriptor.getTitle());
} else if (DialogDescriptor.PROP_NO_DEFAULT_CLOSE.equals(evt.getPropertyName())) {
setDefaultCloseOperation( descriptor instanceof WizardDescriptor || descriptor.isNoDefaultClose()
? JDialog.DO_NOTHING_ON_CLOSE : JDialog.DISPOSE_ON_CLOSE );
} else if (DialogDescriptor.PROP_HELP_CTX.equals(evt.getPropertyName())) {
// bugfix #40057, restore focus owner after help update
Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
updateHelp();
// In case buttons have changed: //just buttons!!
// note, currentButtonsPanel may be null
if (currentButtonsPanel != null) {
currentButtonsPanel.revalidate();
}
if (currentButtonsPanel != null) {
currentButtonsPanel.repaint();
}
if (fo != null) fo.requestFocus();
} else if (DialogDescriptor.PROP_VALID.equals(evt.getPropertyName())) {
updateOKButton(((Boolean)(evt.getNewValue())).booleanValue());
} else if (NotifyDescriptor.PROP_INFO_NOTIFICATION.equals (evt.getPropertyName ())) {
// XXX: need set update on true?
updateNotificationLine (MSG_TYPE_INFO, evt.getNewValue ());
} else if (NotifyDescriptor.PROP_WARNING_NOTIFICATION.equals (evt.getPropertyName ())) {
// XXX: need set update on true?
updateNotificationLine (MSG_TYPE_WARNING, evt.getNewValue ());
} else if (NotifyDescriptor.PROP_ERROR_NOTIFICATION.equals (evt.getPropertyName ())) {
// XXX: need set update on true?
updateNotificationLine (MSG_TYPE_ERROR, evt.getNewValue ());
}
if (update) {
Dimension sz = getSize();
Dimension prefSize = getPreferredSize();
if (prefSize.width > sz.width || prefSize.height > sz.height) {
setSize(Math.max(prefSize.width, sz.width),
Math.max(prefSize.height, sz.height));
}
invalidate();
validate();
repaint();
}
}