@Override public void paintIcon(Component c, Graphics graphics, int x, int y) { Graphics2D g2 = (Graphics2D) graphics.create(); g2.setColor(Color.WHITE); int width = getIconWidth(); int height = getIconHeight(); g2.drawRect(1, 1, width - 2, height - 2); g2.setFont(font); g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = fm.getStringBounds(HELP_STRING, g2); float xPos = (float) ((width - bounds.getWidth()) / 2); int ascent = fm.getAscent(); int descent = fm.getDescent(); float yPos = ((height + 1) / 2 - (ascent + descent) / 2 + ascent); g2.drawString(HELP_STRING, xPos, yPos); g2.translate(-x, -y); } }
private void addViewManipulationActions() { // View manipulation toolbar ViewBanner viewBanner = viewBarComponent.getViewBar().getViewBanner(); plugin.getHelpLink().ifPresent(u -> viewBanner.addAction("Help", HelpIcon.get(), this::showHelpIfPresent)); viewBanner.addAction("Split vertically", SplitVerticallyIcon.get(), this::splitVertically); viewBanner.addAction("Split horizontally", SplitHorizontallyIcon.get(), this::splitHorizontally); viewBanner.addAction("Float", FloatIcon.get(), this::copyAndFloatView); viewBanner.addAction("Close", CloseIcon.get(), this::closeView); }
KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.META_MASK), JComponent.WHEN_FOCUSED); Icon helpIcon = HelpIcon.get(); JButton patternHelpButton = new JButton( new AbstractAction(null, helpIcon) {