javax.swing.JTabbedPane#getComponentAt ( )源码实例Demo

下面列出了javax.swing.JTabbedPane#getComponentAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: RefactoringPanelContainer.java
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();
        }
    }
}
 
源代码2 项目: netbeans   文件: RefactoringPanelContainer.java
@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();
    }
}
 
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);
        }
    });
}
 
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!");
            }
        }
    }
 
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;
}
 
源代码6 项目: zap-extensions   文件: CloseActionHandler.java
@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);
    }
}
 
源代码7 项目: radiance   文件: TabPreviewThread.java
/**
 * 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));
	}
}
 
源代码8 项目: ramus   文件: Control.java
private void openTab(Component component, JTabbedPane pane) {
    for (int i = 0; i < pane.getTabCount(); i++) {
        if (component == pane.getComponentAt(i)) {
            pane.setSelectedIndex(i);
            break;
        }
    }
}
 
源代码9 项目: SikuliX1   文件: CloseableTabbedPane.java
/**
 * 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);
      }
    }
  }
}
 
源代码10 项目: ramus   文件: CloseableTabbedPane.java
/**
 * 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);
            }
        }
    }
}
 
源代码11 项目: CodenameOne   文件: BasicOutlookBarUI.java
public Rectangle getTabBounds(JTabbedPane pane, int index) {
  Component tab = pane.getComponentAt(index);
  return tab.getBounds();
}