javax.swing.plaf.basic.BasicGraphicsUtils Java Examples

The following examples show how to use javax.swing.plaf.basic.BasicGraphicsUtils. 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: DefaultTreeCellRenderer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #2
Source File: DefaultTreeCellRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #3
Source File: DefaultTreeCellRenderer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #4
Source File: XCheckboxPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #5
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testStringClip() {

        String str = "1234567890";
        JComponent comp = createComponent(str);
        FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());

        int width = (int) BasicGraphicsUtils.getStringWidth(comp, fontMetrics, str);

        String clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, width);
        checkClippedString(str, clip, str);

        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, width + 1);
        checkClippedString(str, clip, str);

        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, -1);
        checkClippedString(str, clip, "...");

        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, 0);
        checkClippedString(str, clip, "...");

        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics,
                str, width - width / str.length());
        int endIndex = str.length() - 3;
        checkClippedString(str, clip, str.substring(0, endIndex) + "...");
    }
 
Example #6
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testDrawEmptyString() {
    JLabel label = new JLabel();
    BufferedImage buffImage = createBufferedImage(50, 50);
    Graphics2D g2 = buffImage.createGraphics();
    g2.setColor(DRAW_COLOR);
    BasicGraphicsUtils.drawString(null, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(label, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(null, g2, "", 0, 0);
    BasicGraphicsUtils.drawString(label, g2, "", 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, "", 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, "", 3, 0, 0);
    g2.dispose();
    checkImageIsEmpty(buffImage);
}
 
Example #7
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNullArgumentsDrawString(JComponent comp, Graphics2D g,
        String text) {

    float x = 50;
    float y = 50;
    BasicGraphicsUtils.drawString(null, g, text, x, y);
    BasicGraphicsUtils.drawString(comp, g, null, x, y);

    try {
        BasicGraphicsUtils.drawString(comp, null, text, x, y);
    } catch (NullPointerException e) {
        return;
    }

    throw new RuntimeException("NPE is not thrown");
}
 
Example #8
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNullArgumentsDrawStringUnderlineCharAt(
        JComponent comp, Graphics2D g, String text) {

    int x = 50;
    int y = 50;
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g, text, 1, x, y);
    BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g, null, 1, x, y);

    try {
        BasicGraphicsUtils.drawStringUnderlineCharAt(comp, null, text, 1, x, y);
    } catch (NullPointerException e) {
        return;
    }

    throw new RuntimeException("NPE is not thrown");
}
 
Example #9
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNullArgumentsGetClippedString(
        JComponent comp, String text) {

    FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());

    BasicGraphicsUtils.getClippedString(null, fontMetrics, text, 1);
    String result = BasicGraphicsUtils.getClippedString(comp, fontMetrics, null, 1);
    if (!"".equals(result)) {
        throw new RuntimeException("Empty string is not returned!");
    }

    try {
        BasicGraphicsUtils.getClippedString(comp, null, text, 1);
    } catch (NullPointerException e) {
        return;
    }

    throw new RuntimeException("NPE is not thrown");
}
 
Example #10
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNullArgumentsGetStringWidth(JComponent comp,
        String text) {

    FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
    BasicGraphicsUtils.getStringWidth(null, fontMetrics, text);
    float result = BasicGraphicsUtils.getStringWidth(comp, fontMetrics, null);

    if (result != 0) {
        throw new RuntimeException("The string length is not 0");
    }

    try {
        BasicGraphicsUtils.getStringWidth(comp, null, text);
    } catch (NullPointerException e) {
        return;
    }

    throw new RuntimeException("NPE is not thrown");
}
 
Example #11
Source File: DefaultTreeCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #12
Source File: XCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #13
Source File: DefaultTreeCellRenderer.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #14
Source File: DefaultTreeCellRenderer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #15
Source File: XCheckboxPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #16
Source File: DefaultTreeCellRenderer.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #17
Source File: XCheckboxPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #18
Source File: BasicLinkButtonUI.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
protected void paintFocus(
  Graphics g,
  AbstractButton b,
  Rectangle viewRect,
  Rectangle textRect,
  Rectangle iconRect) {
  if (b.getParent() instanceof JToolBar) {
    // Windows doesn't draw the focus rect for buttons in a toolbar.
    return;
  }

  // focus painted same color as text
  int width = b.getWidth();
  int height = b.getHeight();
  g.setColor(getFocusColor());
  BasicGraphicsUtils.drawDashedRect(
    g,
    dashedRectGapX,
    dashedRectGapY,
    width - dashedRectGapWidth,
    height - dashedRectGapHeight);
}
 
Example #19
Source File: MaterialButtonUI.java    From material-ui-swing with MIT License 6 votes vote down vote up
@Override
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();
	FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
	int mnemonicIndex = b.getDisplayedMnemonicIndex();

	if (model.isEnabled()) {
		g.setColor(b.getForeground());
		BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
				textRect.x + getTextShiftOffset(),
				textRect.y + fm.getAscent() + getTextShiftOffset());
	} else {
		g.setColor(disabledForeground);
		BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
				textRect.x + getTextShiftOffset(),
				textRect.y + fm.getAscent() + getTextShiftOffset());
	}
}
 
Example #20
Source File: DefaultTreeCellRenderer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #21
Source File: XCheckboxPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #22
Source File: EmphasizedLabelUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
protected void paintEnabledText(JLabel label, Graphics g, String s,
		int textX, int textY) {
	Graphics2D g2 = (Graphics2D) g.create();
	g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	if (fShadowColor != null) {
		g2.setColor(fShadowColor);
		g2.setFont(label.getFont());
		BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX,
				textY + 1);
	}
	g2.setColor(isParentWindowFocused(label) ? fFocusedTextColor
			: fUnfocusedTextColor);
	BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY);
	g2.dispose();
}
 
Example #23
Source File: EmphasizedLabelUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
protected void paintDisabledText(JLabel label, Graphics g, String s,
		int textX, int textY) {
	Graphics2D g2 = (Graphics2D) g.create();
	g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	if (fShadowColor != null) {
		g2.setColor(fShadowColor);
		g2.setFont(label.getFont());
		BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX,
				textY + 1);
	}
	g2.setColor(DEFAULT_DISABLED_FONT_COLOR);
	BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY);
	g2.dispose();
}
 
Example #24
Source File: DefaultTreeCellRenderer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #25
Source File: XCheckboxPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #26
Source File: DefaultTreeCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #27
Source File: XCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #28
Source File: DefaultTreeCellRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example #29
Source File: XCheckboxPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintText(Graphics g, Rectangle textRect, String text) {
    FontMetrics fm = g.getFontMetrics();

    int mnemonicIndex = -1;

    if(isEnabled()) {
        /*** paint the text normally */
        g.setColor(getPeerForeground());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
    }
    else {
        /*** paint the text disabled ***/
        g.setColor(getPeerBackground().brighter());

        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x, textRect.y + fm.getAscent());
        g.setColor(getPeerBackground().darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
                                                     textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
}
 
Example #30
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private void paintFocusRect(Graphics g, int x, int y, int w, int h, Color notColor) {
  Color bsColor = getBorderSelectionColor();
  boolean b = selected || !drawDashedFocusIndicator;
  if (Objects.nonNull(bsColor) && b) {
    g.setColor(bsColor);
    g.drawRect(x, y, w - 1, h - 1);
  }
  if (drawDashedFocusIndicator && Objects.nonNull(notColor)) {
    if (!notColor.equals(treeBgsColor)) {
      treeBgsColor = notColor;
      focusBgsColor = new Color(~notColor.getRGB());
    }
    g.setColor(focusBgsColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
  }
}