List of usage examples for javax.swing.event AncestorEvent getComponent
public JComponent getComponent()
From source file:Main.java
public static void main(String args[]) { final JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b = new JButton("Hide for 5"); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);//from www . j av a2 s . c o m TimerTask task = new TimerTask() { public void run() { frame.setVisible(true); } }; Timer timer = new Timer(); timer.schedule(task, 5000); } }; b.addActionListener(action); AncestorListener ancestor = new AncestorListener() { public void ancestorAdded(AncestorEvent e) { System.out.println("Added"); dumpInfo(e); } public void ancestorMoved(AncestorEvent e) { System.out.println("Moved"); dumpInfo(e); } public void ancestorRemoved(AncestorEvent e) { System.out.println("Removed"); dumpInfo(e); } private void dumpInfo(AncestorEvent e) { System.out.println("\tAncestor: " + name(e.getAncestor())); System.out.println("\tAncestorParent: " + name(e.getAncestorParent())); System.out.println("\tComponent: " + name(e.getComponent())); } private String name(Container c) { return (c == null) ? null : c.getName(); } }; b.addAncestorListener(ancestor); contentPane.add(b, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:idontwant2see.IDontWant2See.java
private AbstractAction getActionInputTitle(final Program p, final String part) { return new AbstractAction(mLocalizer.msg("menu.userEntered", "User entered value")) { public void actionPerformed(final ActionEvent e) { final JCheckBox caseSensitive = new JCheckBox(mLocalizer.msg("caseSensitive", "case sensitive")); String title = p.getTitle(); ArrayList<String> items = new ArrayList<String>(); if (!StringUtils.isEmpty(part)) { String shortTitle = title.trim().substring(0, title.length() - part.length()).trim(); shortTitle = StringUtils.removeEnd(shortTitle, "-").trim(); shortTitle = StringUtils.removeEnd(shortTitle, "(").trim(); items.add(shortTitle + "*"); }/*ww w .j a va 2 s .c o m*/ int index = title.indexOf(" - "); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } items.add(title); index = title.lastIndexOf(':'); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } final JComboBox input = new JComboBox(items.toArray(new String[items.size()])); input.setEditable(true); input.addAncestorListener(new AncestorListener() { public void ancestorAdded(final AncestorEvent event) { event.getComponent().requestFocus(); } public void ancestorMoved(final AncestorEvent event) { } public void ancestorRemoved(final AncestorEvent event) { } }); if (JOptionPane.showConfirmDialog(UiUtilities.getLastModalChildOf(getParentFrame()), new Object[] { mLocalizer.msg("exclusionText", "What should be excluded? (You can use the wildcard *)"), input, caseSensitive }, mLocalizer.msg("exclusionTitle", "Exclusion value entering"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { String test = ""; String result = (String) input.getSelectedItem(); if (result != null) { test = result.replaceAll("\\*+", "\\*").trim(); if (test.length() >= 0 && !test.equals("*")) { mSettings.getSearchList() .add(new IDontWant2SeeListEntry(result, caseSensitive.isSelected())); mSettings.setLastEnteredExclusionString(result); updateFilter(!mSettings.isSwitchToMyFilter()); } } if (test.trim().length() <= 1) { JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("notValid", "The entered text is not valid."), Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } } }; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopWindow.java
public DesktopWindow() { initLayout();/*w w w.j a v a 2 s . c o m*/ delegate = createDelegate(); actionsHolder = new DesktopFrameActionsHolder(this, panel); setWidth("100%"); panel.addAncestorListener(new AncestorListener() { @Override public void ancestorAdded(AncestorEvent event) { SwingUtilities.invokeLater(() -> { if (!isAttachedToRoot) { if (SwingUtilities.getRoot(event.getComponent()) != null) { enableEventListeners(); isAttachedToRoot = true; } } }); } @Override public void ancestorRemoved(AncestorEvent event) { SwingUtilities.invokeLater(() -> { if (isAttachedToRoot) { if (SwingUtilities.getRoot(event.getComponent()) == null) { disableEventListeners(); isAttachedToRoot = false; } } }); } @Override public void ancestorMoved(AncestorEvent event) { // do nothing } }); }
From source file:pl.otros.vfs.browser.auth.UserPassUserAuthenticator.java
@Override protected JPanel getOptionsPanel() { Collection<UserAuthenticationDataWrapper> userAuthenticationDatas = getAuthStore() .getUserAuthenticationDatas(getVfsUriParser().getProtocol().getName(), getVfsUriParser().getHostname()); String[] names = new String[userAuthenticationDatas.size()]; int i = 0;// w w w. j ava2 s . c om for (UserAuthenticationData userAuthenticationData : userAuthenticationDatas) { names[i] = new String(userAuthenticationData.getData(UserAuthenticationData.USERNAME)); i++; } JPanel panel = new JPanel(new MigLayout()); String header = Messages.getMessage("authenticator.enterCredentialsForUrl", getUrl()); panel.add(new JLabel(header), "growx,span"); panel.add(new JLabel(Messages.getMessage("authenticator.username"))); nameTf = new JXComboBox(names); nameTf.setEditable(true); nameTf.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { userSelected(nameTf.getSelectedItem().toString()); } }); AutoCompleteDecorator.decorate(nameTf); nameTf.addAncestorListener(new AncestorListener() { @Override public void ancestorRemoved(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } @Override public void ancestorAdded(AncestorEvent event) { event.getComponent().requestFocusInWindow(); } }); panel.add(nameTf, "wrap, growx, span"); panel.add(new JLabel(Messages.getMessage("authenticator.password"))); passTx = new JPasswordField(15); passTx.setText(getVfsUriParser().getPassword()); panel.add(passTx, "wrap, growx,span"); if (StringUtils.isNotBlank(getVfsUriParser().getUsername())) { nameTf.setSelectedItem(getVfsUriParser().getUsername()); } if (names.length > 0) { nameTf.setSelectedIndex(0); } return panel; }