Java Code Examples for javax.swing.JTabbedPane#getComponentAt()

The following examples show how to use javax.swing.JTabbedPane#getComponentAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactoringPanelContainer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void closeAllButCurrent() {
    Component comp = getComponent(0);
    if (comp instanceof JTabbedPane) {
        JTabbedPane tabs = (JTabbedPane) comp;
        Component current = tabs.getSelectedComponent();
        int tabCount = tabs.getTabCount();
        // #172039: do not use tabs.getComponents()
        Component[] c = new Component[tabCount - 1];
        for (int i = 0, j = 0; i < tabCount; i++) {
            Component tab = tabs.getComponentAt(i);
            if (tab != current) {
                c[j++] = tab;
            }
        }
        for (int i = 0; i < c.length; i++) {
            ((RefactoringPanel) c[i]).close();
        }
    }
}
 
Example 2
Source File: RefactoringPanelContainer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void componentClosed() {
    isVisible = false;
    if (getComponentCount() == 0) {
        return ;
    }
    Component comp = getComponent(0);
    if (comp instanceof JTabbedPane) {
        JTabbedPane pane = (JTabbedPane) comp;
        // #172039: do not use tabs.getComponents()
        Component[] c = new Component[pane.getTabCount()];
        for (int i = 0; i < c.length; i++) {
            c[i] = pane.getComponentAt(i);
        }
        for (int i = 0; i < c.length; i++) {
            ((RefactoringPanel) c[i]).close();
        }
    } else if (comp instanceof RefactoringPanel) {
        ((RefactoringPanel) comp).close();
    }
}
 
Example 3
Source File: DefaultDiffControllerProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testTextualDiffContent () throws Exception {
    File diffFile = new File(getDataDir(), "enhancedview/diff");
    String goldenText = getFileContents(diffFile);
    goldenText = MessageFormat.format(goldenText, new Object[] {"a/", "b/"});

    final JTabbedPane tabbedPane = findTabbedPane(enhanced.getJComponent());
    JPanel p = (JPanel) tabbedPane.getComponentAt(1);
    tabbedPane.setSelectedIndex(1);
    JEditorPane pane = findEditorPane(p);
    assertFalse(pane == null);
    String text = pane.getText();
    for (int i = 0; i < 100; ++i) {
        if (!text.isEmpty()) {
            break;
        }
        Thread.sleep(100);
        text = pane.getText();
    }
    assertEquals(goldenText, text);
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run () {
            tabbedPane.setSelectedIndex(0);
        }
    });
}
 
Example 4
Source File: AccessibleIndexInParentTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test() {

        int N = 5;
        JTabbedPane tabbedPane = new JTabbedPane();

        for (int i = 0; i < N; i++) {
            tabbedPane.addTab("Title: " + i, new JLabel("Component: " + i));
        }

        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
            Component child = tabbedPane.getComponentAt(i);

            AccessibleContext ac = child.getAccessibleContext();
            if (ac == null) {
                throw new RuntimeException("Accessible Context is null!");
            }

            int index = ac.getAccessibleIndexInParent();
            Accessible parent = ac.getAccessibleParent();

            if (parent.getAccessibleContext().getAccessibleChild(index) != child) {
                throw new RuntimeException("Wrong getAccessibleIndexInParent!");
            }
        }
    }
 
Example 5
Source File: TestDataComponent.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
public Boolean navigateToTestData(String sheetName, String columnName) {
    if (envTab.getSelectedComponent() instanceof JTabbedPane) {
        JTabbedPane tab = (JTabbedPane) envTab.getSelectedComponent();
        for (int i = 0; i < tab.getTabCount(); i++) {
            if (tab.getComponentAt(i) instanceof TestDataTablePanel) {
                TestDataTablePanel tdPanel = (TestDataTablePanel) tab.getComponentAt(i);
                if (tdPanel.std.getName().equals(sheetName)) {
                    int colIndex = tdPanel.std.getColumnIndex(columnName);
                    if (colIndex != -1) {
                        tab.setSelectedIndex(i);
                        tdPanel.table.selectColumn(colIndex);
                        return true;
                    }
                    break;
                }
            }
        }
    }
    return false;
}
 
Example 6
Source File: CloseActionHandler.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {

    JTabbedPane ntp = getNumberedTabbedPane();

    int index = ntp.indexOfTab(getTabName());
    if (index >= 0) {
        if (ntp.getTabCount() > 2 && index == ntp.getTabCount() - 2) {
            ntp.setSelectedIndex(index - 1);
        }
        ManualHttpRequestEditorPanel currentEditor =
                (ManualHttpRequestEditorPanel) ntp.getComponentAt(index);
        currentEditor.beforeClose();
        currentEditor.saveConfig();
        ntp.removeTabAt(index);
    }
}
 
Example 7
Source File: TabPreviewThread.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Computes and offers the preview thumbnail for a single tab.
 * 
 * @param tabPane
 *            Tabbed pane.
 * @param previewPainter
 *            Tab preview painter.
 * @param previewInfo
 *            Preview info.
 * @param tabIndex
 *            Index of the tab to preview.
 */
protected void getSingleTabPreviewImage(final JTabbedPane tabPane,
		final TabPreviewPainter previewPainter,
		final TabPreviewInfo previewInfo, final int tabIndex) {
	int pWidth = previewInfo.getPreviewWidth();
	int pHeight = previewInfo.getPreviewHeight();
	final BufferedImage previewImage = SubstanceCoreUtilities.getBlankImage(pWidth, pHeight);
	Component comp = tabPane.getComponentAt(tabIndex);

	if (previewPainter.hasPreview(tabPane, tabIndex)) {
		Map<Component, Boolean> dbSnapshot = new HashMap<>();
		WidgetUtilities.makePreviewable(comp, dbSnapshot);
		previewPainter.previewTab(tabPane, tabIndex, previewImage, 0, 0, pWidth, pHeight);
		WidgetUtilities.restorePreviewable(comp, dbSnapshot);
	} else {
		Graphics2D gr = previewImage.createGraphics();
		gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		gr.setColor(Color.red);
		gr.setStroke(new BasicStroke(Math.max(5.0f, Math.min(pWidth, pHeight) / 10.0f)));
		gr.drawLine(0, 0, pWidth, pHeight);
		gr.drawLine(0, pHeight, pWidth, 0);
		gr.dispose();
	}

	if (previewInfo.previewCallback != null) {
		SwingUtilities.invokeLater(() ->
				previewInfo.previewCallback.offer(tabPane, tabIndex, previewImage));
	}
}
 
Example 8
Source File: Control.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private void openTab(Component component, JTabbedPane pane) {
    for (int i = 0; i < pane.getTabCount(); i++) {
        if (component == pane.getComponentAt(i)) {
            pane.setSelectedIndex(i);
            break;
        }
    }
}
 
Example 9
Source File: CloseableTabbedPane.java    From SikuliX1 with MIT License 4 votes vote down vote up
/**
 * Draw the icon at the specified location. Icon implementations may use the Component argument
 * to get properties useful for painting, e.g. the foreground or background color.
 *
 * @param c the component which the icon belongs to
 * @param g the graphic object to draw on
 * @param x the upper left point of the icon in the x direction
 * @param y the upper left point of the icon in the y direction
 */
public void paintIcon(Component c, Graphics g, int x, int y) {
  boolean doPaintCloseIcon = true;
  try {
    // JComponent.putClientProperty("isClosable", new Boolean(false));
    JTabbedPane tabbedpane = (JTabbedPane) c;
    int tabNumber = tabbedpane.getUI().tabForCoordinate(tabbedpane, x, y);
    JComponent curPanel = (JComponent) tabbedpane.getComponentAt(tabNumber);
    Object prop = null;
    if ((prop = curPanel.getClientProperty("isClosable")) != null) {
      doPaintCloseIcon = (Boolean) prop;
    }
  } catch (Exception ignored) {/*Could probably be a ClassCastException*/

  }
  if (doPaintCloseIcon) {
    x_pos = x;
    y_pos = y;
    int y_p = y + 1;

    if (normalCloseIcon != null && !mouseover) {
      normalCloseIcon.paintIcon(c, g, x, y_p);
    } else if (hooverCloseIcon != null && mouseover && !mousepressed) {
      hooverCloseIcon.paintIcon(c, g, x, y_p);
    } else if (pressedCloseIcon != null && mousepressed) {
      pressedCloseIcon.paintIcon(c, g, x, y_p);
    } else {
      y_p++;

      Color col = g.getColor();

      if (mousepressed && mouseover) {
        g.setColor(Color.WHITE);
        g.fillRect(x + 1, y_p, 12, 13);
      }

      g.setColor(Color.GRAY);
      /*
       g.drawLine(x+1, y_p, x+12, y_p);
       g.drawLine(x+1, y_p+13, x+12, y_p+13);
       g.drawLine(x, y_p+1, x, y_p+12);
       g.drawLine(x+13, y_p+1, x+13, y_p+12);
       g.drawLine(x+3, y_p+3, x+10, y_p+10);
       */
      if (mouseover) {
        g.setColor(Color.RED);
      }
      g.drawLine(x + 3, y_p + 4, x + 9, y_p + 10);
      g.drawLine(x + 4, y_p + 3, x + 10, y_p + 9);
      g.drawLine(x + 10, y_p + 3, x + 3, y_p + 10);
      g.drawLine(x + 10, y_p + 4, x + 4, y_p + 10);
      g.drawLine(x + 9, y_p + 3, x + 3, y_p + 9);
      g.setColor(col);
      if (fileIcon != null) {
        fileIcon.paintIcon(c, g, x + width, y_p);
      }
    }
  }
}
 
Example 10
Source File: CloseableTabbedPane.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw the icon at the specified location. Icon implementations may use
 * the Component argument to get properties useful for painting, e.g.
 * the foreground or background color.
 *
 * @param c the component which the icon belongs to
 * @param g the graphic object to draw on
 * @param x the upper left point of the icon in the x direction
 * @param y the upper left point of the icon in the y direction
 */
public void paintIcon(Component c, Graphics g, int x, int y) {
    boolean doPaintCloseIcon = true;
    try {
        // JComponent.putClientProperty("isClosable", new
        // Boolean(false));
        JTabbedPane tabbedpane = (JTabbedPane) c;
        int tabNumber = tabbedpane.getUI().tabForCoordinate(tabbedpane,
                x, y);
        JComponent curPanel = (JComponent) tabbedpane
                .getComponentAt(tabNumber);
        Object prop = null;
        if ((prop = curPanel.getClientProperty("isClosable")) != null) {
            doPaintCloseIcon = (Boolean) prop;
        }
    } catch (Exception ignored) {/*
                                 * Could probably be a
		 * ClassCastException
		 */
    }
    if (doPaintCloseIcon) {
        x_pos = x;
        y_pos = y;
        int y_p = y + 1;

        if (normalCloseIcon != null && !mouseover) {
            normalCloseIcon.paintIcon(c, g, x, y_p);
        } else if (hooverCloseIcon != null && mouseover
                && !mousepressed) {
            hooverCloseIcon.paintIcon(c, g, x, y_p);
        } else if (pressedCloseIcon != null && mousepressed) {
            pressedCloseIcon.paintIcon(c, g, x, y_p);
        } else {
            y_p++;

            Color col = g.getColor();

            if (mousepressed && mouseover) {
                g.setColor(Color.WHITE);
                g.fillRect(x + 1, y_p, 12, 13);
            }

            g.setColor(Color.black);
            g.drawLine(x + 1, y_p, x + 12, y_p);
            g.drawLine(x + 1, y_p + 13, x + 12, y_p + 13);
            g.drawLine(x, y_p + 1, x, y_p + 12);
            g.drawLine(x + 13, y_p + 1, x + 13, y_p + 12);
            g.drawLine(x + 3, y_p + 3, x + 10, y_p + 10);
            if (mouseover)
                g.setColor(Color.GRAY);
            g.drawLine(x + 3, y_p + 4, x + 9, y_p + 10);
            g.drawLine(x + 4, y_p + 3, x + 10, y_p + 9);
            g.drawLine(x + 10, y_p + 3, x + 3, y_p + 10);
            g.drawLine(x + 10, y_p + 4, x + 4, y_p + 10);
            g.drawLine(x + 9, y_p + 3, x + 3, y_p + 9);
            g.setColor(col);
            if (fileIcon != null) {
                fileIcon.paintIcon(c, g, x + width, y_p);
            }
        }
    }
}
 
Example 11
Source File: BasicOutlookBarUI.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public Rectangle getTabBounds(JTabbedPane pane, int index) {
  Component tab = pane.getComponentAt(index);
  return tab.getBounds();
}