List of usage examples for java.awt Component equals
public boolean equals(Object obj)
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane;/*from w w w. jav a 2s. co m*/ JTextField txtFoo = new JTextField(10); JPanel pnlFoo = new JPanel(); pnlFoo.add(new JButton("Button 1")); pnlFoo.add(new JLabel("Foo")); pnlFoo.add(txtFoo); JTextField txtBar = new JTextField(10); JPanel pnlBar = new JPanel(); pnlBar.add(new JButton("Button 3")); pnlBar.add(new JLabel("Bar")); pnlBar.add(txtBar); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tab 1", pnlFoo); tabbedPane.addTab("Tab 2", pnlBar); tabbedPane.addChangeListener(e -> { Component comp = tabbedPane.getSelectedComponent(); if (comp.equals(pnlFoo)) { txtFoo.requestFocusInWindow(); } else if (comp.equals(pnlBar)) { txtBar.requestFocusInWindow(); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(460, 200); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); frame.setVisible(true); txtFoo.requestFocusInWindow(); }
From source file:Main.java
public static void showAsOnlyVisibleChild(JComponent container, Component childToBeMadeVisible) { for (Component child : container.getComponents()) { boolean visible = child.equals(childToBeMadeVisible); child.setVisible(visible);/*from w ww . j a va 2 s . c om*/ if (visible) { container.getLayout().addLayoutComponent(BorderLayout.CENTER, child); } else { container.getLayout().removeLayoutComponent(child); } child.repaint(); } container.revalidate(); container.repaint(); }
From source file:Main.java
public static int getIndex(Container parent, Component child) { for (int i = 0; i < parent.getComponentCount(); i++) { if (child.equals(parent.getComponent(i))) return i; }/*from w w w . j a va 2 s .com*/ return -1; }
From source file:Main.java
public static void replaceComponent(Container cont, Component comp1, Component comp2, String constraints) { int index = -1; int i = 0;/* w ww .j a v a 2 s . c om*/ for (Component comp : cont.getComponents()) { if (comp.equals(comp1)) { index = i; break; } ++i; } // cont.setIgnoreRepaint(true); cont.remove(comp1); cont.add(comp2, constraints, index); cont.validate(); // cont.setIgnoreRepaint(false); cont.repaint(); }
From source file:components.GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { //we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { //The mouse event is over the menu bar. //Could handle specially. } else {/*from w ww .j a v a 2 s .com*/ //The mouse event is over non-system window //decorations, such as the ones provided by //the Java look and feel. //Could handle specially. } } else { //The mouse event is probably over the content pane. //Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { //Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } //Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { // we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { // The mouse event is over the menu bar. // Could handle specially. } else {/*from w ww. ja v a 2 s . c o m*/ // The mouse event is over non-system window // decorations, such as the ones provided by // the Java look and feel. // Could handle specially. } } else { // The mouse event is probably over the content pane. // Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { // Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } // Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:org.rdv.viz.spectrum.SpectrumViz.java
/** * Handle events from the properties panel. * //from w ww .j a va 2 s. c om * @param source the source of the event */ private void handlePropertiesUpdate(Component source) { if (source == null) return; if (source.equals(sampleRateTextField)) { handleSampleRateUpdate(); } else if (source.equals(numberOfSamplesTextField)) { handleNumberOfSamplesUpdate(); } else if (source.equals(windowFunctionComboBox)) { handleWindowFunctionUpdate(); } else if (source.equals(segmentSizeTextField)) { handleSegmentSizeUpdate(); } else if (source.equals(overlapTextField)) { handleOverlapUpdate(); } }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * {@inheritDoc}/* www .j a v a 2 s . co m*/ */ protected List getComponentContext(Object component) { Component comp = (Component) component; List context = new ArrayList(); if (comp.getParent() != null) { SwingHierarchyContainer parent = getHierarchyContainer(comp.getParent()); if (parent != null) { SwingHierarchyContainer[] comps = parent.getComponents(); for (int i = 0; i < comps.length; i++) { Component child = comps[i].getComponentID().getRealComponent(); if (!child.equals(comp)) { String toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + 1; while (context.contains(toAdd)) { int lastCount = Integer .valueOf(toAdd .substring(toAdd.lastIndexOf(Constants.CLASS_NUMBER_SEPERATOR) + 1)) .intValue(); toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + (lastCount + 1); } context.add(toAdd); } } } } return context; }
From source file:com.jvms.i18neditor.editor.Editor.java
private void setupGlobalKeyEventDispatcher() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> { if (e.getID() != KeyEvent.KEY_PRESSED || !e.isAltDown() || (SystemUtils.IS_OS_MAC && !e.isMetaDown()) || (!SystemUtils.IS_OS_MAC && !e.isShiftDown())) { return false; }/*from ww w .j a va2s . co m*/ TreePath selected = translationTree.getSelectionPath(); if (selected == null) { return false; } boolean result = false; int row = translationTree.getRowForPath(selected); switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: if (!translationTree.isExpanded(row)) { translationTree.expandRow(row); } result = true; break; case KeyEvent.VK_LEFT: if (translationTree.isCollapsed(row)) { translationTree.setSelectionPath(selected.getParentPath()); } else { translationTree.collapseRow(row); } result = true; break; case KeyEvent.VK_UP: TreePath prev = translationTree.getPathForRow(Math.max(0, row - 1)); if (prev != null) { translationTree.setSelectionPath(prev); } result = true; break; case KeyEvent.VK_DOWN: TreePath next = translationTree.getPathForRow(row + 1); if (next != null) { translationTree.setSelectionPath(next); } result = true; break; } if (result && !resourceFields.isEmpty()) { Component comp = getFocusOwner(); if (comp != null && (comp instanceof ResourceField || comp.equals(this))) { TranslationTreeNode current = translationTree.getSelectionNode(); if (!current.isLeaf() || current.isRoot()) { requestFocusInWindow(); } else if (comp.equals(this)) { requestFocusInFirstResourceField(); } } } return result; }); }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * Investigates the given <code>component</code> for an identifier. To * obtain this identifier the name of the component and the container * hierarchy is used.//from w w w. j a va2 s .co m * @param component the component to create an identifier for, must not be null. * @throws ComponentNotManagedException if component is null or <br> * (one of the) component(s) in the hierarchy is not managed * @return the identifier for <code>component</code> */ public IComponentIdentifier getComponentIdentifier(Component component) throws ComponentNotManagedException { checkDispatchThread(); IComponentIdentifier result = new ComponentIdentifier(); try { // fill the componentIdentifier result.setComponentClassName(component.getClass().getName()); result.setSupportedClassName( AUTServerConfiguration.getInstance().getTestableClass(component.getClass()).getName()); List hierarchy = getPathToRoot(component); result.setHierarchyNames(hierarchy); result.setNeighbours(getComponentContext(component)); HierarchyContainer container = getHierarchyContainer(component); setAlternativeDisplayName(container, component, result); if (component.equals(findBP.findComponent(result, ComponentHandler.getAutHierarchy()))) { result.setEqualOriginalFound(true); } return result; } catch (IllegalArgumentException iae) { // from getPathToRoot() log.error(iae); throw new ComponentNotManagedException("getComponentIdentifier() called for an unmanaged component: " //$NON-NLS-1$ + component, MessageIDs.E_COMPONENT_NOT_MANAGED); // let pass the ComponentNotManagedException from getPathToRoot() } }