Java Code Examples for java.awt.Graphics#setFont()

The following examples show how to use java.awt.Graphics#setFont() . 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: Clock.java    From hottub with GNU General Public License v2.0 7 votes vote down vote up
@Override
public void paint(Graphics g) {
    g.setFont(clockFaceFont);
    // Draw the circle and numbers
    g.setColor(handColor);
    g.drawArc(xcenter - 50, ycenter - 50, 100, 100, 0, 360);
    g.setColor(numberColor);
    g.drawString("9", xcenter - 45, ycenter + 3);
    g.drawString("3", xcenter + 40, ycenter + 3);
    g.drawString("12", xcenter - 5, ycenter - 37);
    g.drawString("6", xcenter - 3, ycenter + 45);

    // Draw date and hands
    g.setColor(numberColor);
    g.drawString(lastdate, 5, 125);
    g.drawLine(xcenter, ycenter, lastxs, lastys);
    g.setColor(handColor);
    g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
    g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
    g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
    g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
 
Example 2
Source File: CallPanelButton.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int width = getWidth();
    int height = getHeight();

    int x = (width - backgroundImage.getWidth(null)) / 2;
    int y = (height - backgroundImage.getHeight(null)) / 2;
    g.drawImage(backgroundImage, x, y - 5, null);

    if (isEnabled()) {
        g.setColor(Color.black);
    }
    else {
        g.setColor(Color.lightGray);
    }
    g.setFont(new Font("Dialog", Font.PLAIN, 11));


    int stringWidth = g.getFontMetrics().stringWidth(text);

    x = (width - stringWidth) / 2;
    y = height - 12;
    g.drawString(text, x, y);

}
 
Example 3
Source File: Slider.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintInstance(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds bds = painter.getBounds();
	SliderValue data = getValueState(painter);
	int x = bds.getX(), y = bds.getY();
	painter.drawRoundBounds(painter.getAttributeValue(Io.ATTR_COLOR));
	GraphicsUtil.switchToWidth(g, 2);
	// slider line
	g.drawLine(x + 10, y + bds.getHeight() - 10, x + bds.getWidth() - 10, y + bds.getHeight() - 10);
	g.setColor(Color.DARK_GRAY);
	// slider
	g.fillRoundRect(x + data.getCurrentX() + 5, y + bds.getHeight() - 15, 10, 10, 4, 4);
	g.setColor(Color.BLACK);
	g.drawRoundRect(x + data.getCurrentX() + 5, y + bds.getHeight() - 15, 10, 10, 4, 4);
	painter.drawPorts();
	painter.drawLabel();
	// paint current value
	g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 9));
	Value v = painter.getPort(0);
	FontMetrics fm = g.getFontMetrics();
	RadixOption radix = painter.getAttributeValue(RadixOption.ATTRIBUTE);
	String vStr = radix.toString(v);
	// if the string is too long, reduce its dimension
	if (fm.stringWidth(vStr) > bds.getWidth() - 10)
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 5));
	GraphicsUtil.drawCenteredText(g, vStr, x + bds.getWidth() / 2, y + 6);
}
 
Example 4
Source File: PrintLatinCJKTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pf, int pageIndex)
                     throws PrinterException {

    if (pageIndex > 0) {
        return Printable.NO_SUCH_PAGE;
    }
    g.translate((int) pf.getImageableX(), (int) pf.getImageableY());
    g.setFont(new Font("Dialog", Font.PLAIN, 36));
    g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100);
    return Printable.PAGE_EXISTS;
}
 
Example 5
Source File: FutureRatioCellRenderer.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param g
 */
public void paint(Graphics g) {
    if (mePaint) {
        g.setColor(Color.white);
   // } else {
        //     g.setColor(selection);
    }
   // g.fillRect(0, 0, getWidth()-1, getHeight()-1);

    super.paint(g);
    g.setColor(Color.black);
    g.setFont(new Font("Monospaced", Font.PLAIN, 11));//was courier

    String data[] = this.getText().split(":");
    StringBuilder ratio = new StringBuilder();
    StringBuilder stdErr = new StringBuilder();

    Formatter ratioFormatter = new Formatter(ratio);
    Formatter stdErrFormatter = new Formatter(stdErr);

    try {
        ratioFormatter.format("%9.4f", Double.valueOf(data[0].trim()));
        stdErrFormatter.format("%9.4f", Double.valueOf(data[1].trim()));
    } catch (Exception e) {
        ratioFormatter.format("%9.4f", 0.0);
        stdErrFormatter.format("%9.4f", 0.0);

    }
}
 
Example 6
Source File: SynthLabelUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JLabel label = (JLabel)context.getComponent();
    Icon icon = (label.isEnabled()) ? label.getIcon() :
                                      label.getDisabledIcon();

    g.setColor(context.getStyle().getColor(context,
                                           ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context.getStyle().getGraphicsUtils(context).paintText(
        context, g, label.getText(), icon,
        label.getHorizontalAlignment(), label.getVerticalAlignment(),
        label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
        label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0);
}
 
Example 7
Source File: PbRatioCellRenderer.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param g
 */
@Override
public void paint(Graphics g) {
    if (mePaint){
        g.setColor(ReduxConstants.ColorOfLead);
    }
    
    super.paint(g);
    
    g.setColor(Color.black);
    g.setFont(new Font("Monospaced", Font.BOLD, 11));
    
    String data[] = this.getText().split(":");
    StringBuilder ratio = new StringBuilder();
    StringBuilder stdErr = new StringBuilder();
    
    Formatter ratioFormatter = new Formatter(ratio);
    Formatter stdErrFormatter = new Formatter(stdErr);
    
    try {
        ratioFormatter.format("%9.4f", Double.valueOf(data[0].trim()));
        g.drawString(ratio.substring(0),
                (int)g.getClipBounds().getWidth() - 70, 12); // hard-coded for now 2,12);
        stdErrFormatter.format("%9.4f", Double.valueOf(data[1].trim()));
        g.drawString(stdErr.substring(0),
                (int)g.getClipBounds().getWidth() - 70, 27);//, 2,27);
    } catch(Exception e) {
        // april 2010 draw whatever is there, for LAGACY = "n/a"
        g.drawString(data[0].trim(),
                (int)g.getClipBounds().getWidth() - 35 - data[0].trim().length() / 2, 20); // hard-coded for now 2,12);
    }
}
 
Example 8
Source File: SynthLabelUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JLabel label = (JLabel)context.getComponent();
    Icon icon = (label.isEnabled()) ? label.getIcon() :
                                      label.getDisabledIcon();

    g.setColor(context.getStyle().getColor(context,
                                           ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context.getStyle().getGraphicsUtils(context).paintText(
        context, g, label.getText(), icon,
        label.getHorizontalAlignment(), label.getVerticalAlignment(),
        label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
        label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0);
}
 
Example 9
Source File: TextRenderTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TextContext tctx = (TextContext)ctx;
    Graphics g = tctx.graphics;
    g.setFont(tctx.font);
    try {
        byte[] bytes = tctx.text.getBytes("ASCII"); // only good for english
        do {
            g.drawBytes(bytes, 0, bytes.length, 40, 40);
        } while (--numReps >= 0);
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: DiacriticsDrawingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static BufferedImage drawString(String text) {
    BufferedImage image = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
    g.setColor(Color.black);
    g.setFont(FONT);
    g.drawString(text, TEXT_X, TEXT_Y);
    g.dispose();
    return image;
}
 
Example 11
Source File: CheckBox.java    From DroidUIBuilder with Apache License 2.0 4 votes vote down vote up
@Override
public void paint(Graphics g)
{
	// 绘制背景
	super.paintBackground(g);// 注意:不能调用super.paint()哦
	
	Image img;
	int off_x;
	int off_y;

	if (on == null || off == null)
	{
		g.setColor(Color.white);
		g.fillRect(getX() + 2, getY() + 2, 16, 16);

		g.setColor(Color.black);
		g.drawRect(getX() + 2, getY() + 2, 16, 16);

		if ("true".equals(this.getPropertyByAttName("android:checked")
				.getValue()))
		{
			g.drawLine(getX() + 2, getY() + 2, getX() + 18, getY() + 18);
			g.drawLine(getX() + 2, getY() + 18, getX() + 18, getY() + 2);
		}
		off_x = 20;
		off_y = 18;
	}
	else
	{
		if ("true".equals(this.getPropertyByAttName("android:checked")
				.getValue()))
		{
			img = on;
		}
		else
		{
			img = off;
		}
		g.drawImage(img, getX(), getY(), null);
		g.setColor(Color.black);
		off_x = img.getWidth(null);
		off_y = img.getHeight(null);
	}
	
	baseline = (off_y + fontSize) / 2;
	setTextColor(g);
	g.setFont(f);
	// 开启字体绘制反走样
	Utils.setTextAntiAliasing((Graphics2D)g, true);
	g.drawString(text.getStringValue(), getX() + off_x, getY() + baseline - 4);
	// 绘制完成后并闭字体绘制反走样
	Utils.setTextAntiAliasing((Graphics2D)g, false);
}
 
Example 12
Source File: ChatterBox2.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the chatter box.
 */
public void draw(Graphics graph, Rectangle clipBounds) {
    graph.setColor(COLOR_BACKGROUND);
    graph.setFont(FONT_CHAT);

    // Draw box.
    int yOffset = ((clipBounds.height) - height - DIST_BOTTOM) + slideOffset + clipBounds.y;
    //graph.fillRoundRect(DIST_SIDE + clipBounds.x, yOffset, width, height, 20, 20);
    graph.fillRect(DIST_SIDE + clipBounds.x, yOffset, width, height);
    graph.setColor(COLOR_TEXT_BACK);

    // Min/max button
    if (slideOffset == getMaxSlideOffset()) {
        graph.drawImage(maxbutton, 10 + clipBounds.x, yOffset + 3, bv);
    } else {
        graph.drawImage(minbutton, 10 + clipBounds.x , yOffset + 3, bv);
    }

    // Title
    printLine(graph, "Incoming messages...", 29 + clipBounds.x, yOffset + 15);

    // resize button
    graph.drawImage(resizebutton, (width - 16) + clipBounds.x, yOffset + 3, bv);

    // Scroll up button
    graph.drawImage(upbutton, (width - 16) + clipBounds.x, yOffset + 16, bv);

    // Scroll bar outer
    graph.drawRect((width - 16) + clipBounds.x, yOffset + 30, 13, getScrollbarOuterHeight());

    // Scroll bar inner
    graph.drawRect((width - 14) + clipBounds.x, yOffset + 31 + scrollBarOffset, 9, scrollBarHeight);

    // Scroll down button
    graph.drawImage(downbutton, (width - 16) + clipBounds.x, (yOffset + height) - 20, bv);

    // Message box
    graph.drawRect(10 + clipBounds.x, (yOffset + height) - 21, width - 50, 17);
    if (message != null && bv.getChatterBoxActive()) {
        printLine(graph, visibleMessage + "_", 13 + clipBounds.x, (yOffset + height) - 7);
    }

    // Text rows
    int rows = messages.size();
    if (rows <= max_nbr_rows) {
        for (int i = 0; i < messages.size(); i++) {
            printLine(graph, messages.elementAt(i), 10 + clipBounds.x, yOffset
                    + 15 + ((i + 1) * 15));
        }
    } else {
        int row = 1;
        for (int i = rows - max_nbr_rows - chatScroll; i < (messages
                .size()
                - chatScroll); i++) {
            if (i > -1) {
                printLine(graph, messages.elementAt(i), 10 + clipBounds.x, yOffset
                        + 15 + (row * 15));
                row++;
            }
        }
    }
}
 
Example 13
Source File: PButton.java    From PolyGlot with MIT License 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    boolean enabled = isEnabled();
    Color bgColor;
    Color fontColor;
    final int thisHeight = getHeight();
    final int thisWidth = getWidth();
    
    if (!enabled) {
        bgColor = PGTUtil.COLOR_DISABLED_BG;
        fontColor = PGTUtil.COLOR_DISABLED_FOREGROUND;
    } else if (mousePressed && mouseEntered) {
        bgColor = PGTUtil.COLOR_SELECTED_BG;
        fontColor = getForeground();
    } else {
        bgColor = PGTUtil.COLOR_ENABLED_BG;
        fontColor = getForeground();
    }
    
    if (activeSelected) {
        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());
    }
    
    // turn on anti-alias mode
    Graphics2D antiAlias = (Graphics2D) g;
    antiAlias.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setColor(bgColor);
    
    g.fillRect(2, 2, thisWidth - 4, thisHeight - 4);

    // draw black border on mouseover if button enabled
    if (mouseEntered && enabled) {
        g.setColor(PGTUtil.COLOR_MOUSEOVER_BORDER);
        g.drawRect(1, 1, thisWidth - 3, thisHeight - 3);
    }
    
    g.setColor(fontColor);
    g.setFont(getFont());
    
    char[] text = getText().toCharArray();
    FontMetrics fm = g.getFontMetrics(getFont());
    Rectangle2D rec = fm.getStringBounds(getText(), g);
    int stringW = (int) Math.round(rec.getWidth());
    int stringH = (int) Math.round(rec.getHeight());
    g.drawChars(text, 0, text.length, (thisWidth/2) - (stringW/2), thisHeight/2 + stringH/4);
    
    Icon icon = this.getIcon();
    if (icon != null) {
        icon.paintIcon(this, g, (thisWidth -icon.getIconWidth())/2, (thisHeight - icon.getIconHeight())/2);
    }
}
 
Example 14
Source File: LineLabel.java    From RegexReplacer with MIT License 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	Graphics g2 = g.create();
	Rectangle clipRect = g2.getClipBounds();
	if (isOpaque()) {
		g2.setColor(getBackground());
		g2.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
	}
	g2.setColor(getForeground());
	g2.setFont(getFont());
	Document document = jTextComponent.getDocument();
	Graphics greyG2 = g2.create();
	greyG2.setColor(repetitiveLineColor);
	try {
		Element rootElement;
		if (document instanceof AbstractDocument)
			((AbstractDocument) document).readLock();
		rootElement = document.getDefaultRootElement();
		FontMetrics myFontMetrics = getFontMetrics(getFont());
		FontMetrics textFontMetrics = jTextComponent
				.getFontMetrics(jTextComponent.getFont());
		TextUI ui = jTextComponent.getUI();
		int rowNum = rootElement.getElementIndex(ui.viewToModel(
				jTextComponent, clipRect.getLocation()));
		int ascent = textFontMetrics.getAscent();
		int rowHeight = textFontMetrics.getHeight();
		Element element = rootElement.getElement(rowNum);
		if (element == null)
			return;
		String rowNumStr = "";
		int x = 0, y, nextY, originalStartY, maxY;
		try {
			originalStartY = ui.modelToView(jTextComponent,
					element.getStartOffset()).y;
			maxY = ui.modelToView(jTextComponent,
					rootElement.getEndOffset() - 1).y;
		} catch (BadLocationException e1) {
			return;
		}
		maxY = Math.min(maxY, clipRect.y + clipRect.height);
		y = originalStartY;
		if (y < clipRect.y)
			y = clipRect.y - (clipRect.y - y) % rowHeight;
		nextY = 0;
		for (; y <= maxY; y += rowHeight) {
			if (y < nextY) {
				greyG2.drawString(rowNumStr, x, y + ascent);
			} else {
				rowNumStr = String.valueOf(rowNum + 1);
				x = width - offset - myFontMetrics.stringWidth(rowNumStr);
				// nextY == 0 means that it's the first time
				if (nextY != 0 || y == originalStartY)
					g2.drawString(rowNumStr, x, y + ascent);
				else
					y -= rowHeight;
				rowNum++;
				if (rowNum >= rowCount)
					nextY = Integer.MAX_VALUE;
				else
					try {
						nextY = ui.modelToView(jTextComponent, rootElement
								.getElement(rowNum).getStartOffset()).y;
					} catch (BadLocationException e) {
						break;
					}
			}
		}
	} finally {
		if (document instanceof AbstractDocument)
			((AbstractDocument) document).readUnlock();
		g2.dispose();
		greyG2.dispose();
	}
}
 
Example 15
Source File: MultimonFullscreenTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void renderDimensions(Graphics g, Rectangle rectWndBounds,
                             GraphicsConfiguration gc) {
    g.setColor(new Color(rnd.nextInt(0xffffff)));
    g.fillRect(0, 0, rectWndBounds.width, rectWndBounds.height);

    g.setColor(new Color(rnd.nextInt(0xffffff)));
    Rectangle rectStrBounds;

    g.setFont(f);

    rectStrBounds = g.getFontMetrics().
            getStringBounds(rectWndBounds.toString(), g).getBounds();
    rectStrBounds.height += 30;
    g.drawString(rectWndBounds.toString(), 50, rectStrBounds.height);
    int oldHeight = rectStrBounds.height;
    String isFSupported = "Exclusive Fullscreen mode supported: " +
                          gc.getDevice().isFullScreenSupported();
    rectStrBounds = g.getFontMetrics().
            getStringBounds(isFSupported, g).getBounds();
    rectStrBounds.height += (10 + oldHeight);
    g.drawString(isFSupported, 50, rectStrBounds.height);

    oldHeight = rectStrBounds.height;
    String isDMChangeSupported = "Display Mode Change supported: " +
                          gc.getDevice().isDisplayChangeSupported();
    rectStrBounds = g.getFontMetrics().
            getStringBounds(isDMChangeSupported, g).getBounds();
    rectStrBounds.height += (10 + oldHeight);
    g.drawString(isDMChangeSupported, 50, rectStrBounds.height);

    oldHeight = rectStrBounds.height;
    String usingBS = "Using BufferStrategy: " + useBS;
    rectStrBounds = g.getFontMetrics().
            getStringBounds(usingBS, g).getBounds();
    rectStrBounds.height += (10 + oldHeight);
    g.drawString(usingBS, 50, rectStrBounds.height);

    final String m_strQuitMsg = "Double-click to dispose FullScreen Window";
    rectStrBounds = g.getFontMetrics().
            getStringBounds(m_strQuitMsg, g).getBounds();
    g.drawString(m_strQuitMsg,
            (rectWndBounds.width - rectStrBounds.width) / 2,
            (rectWndBounds.height - rectStrBounds.height) / 2);


}
 
Example 16
Source File: OSVBatteryWidget.java    From osv with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	setOurWidth();
	int x = getWidth();
	int y = getHeight();

	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.setColor(OSVColors.GREY_3);
	int offX = x / 5;
	int offY = y / 3;
	int width = x * 3 / 5;
	int height = y * 2 / 5;
	g2d.fillRect(offX, offY, width, height);

	if (soc > 0f) {
		g2d.setColor(OSVColors.BLUE_1);
		int maxHeight = 5 * height / 8 - width / 10;
		g2d.fillRect(offX + width / 4 + width / 20, (int) (offY + height / 8 + width / 20 + (1 - soc) * maxHeight),
				width / 2 - width / 10, (int) (5 * height / 8 - width / 10 - (1 - soc) * maxHeight));
	}

	g2d.setStroke(new BasicStroke(6));
	g2d.setColor(OSVColors.WHITE);
	g2d.drawRect(offX + width / 4, offY + height / 8, width / 2, 5 * height / 8);
	g2d.drawRect(offX + width / 4 + width / 8, offY + height / 8 - height / 20, width / 4, height / 20);

	if (isCharging) {
		// TODO Draw lightning
		int ySize = height / 2;
		int xSize = mw.chargeLightning.getWidth() * ySize / mw.chargeLightning.getHeight();
		BufferedImage lightningImg;
		switch (lightningCounter++) {
		case 0:
			lightningImg = mw.chargeLightning0;
			break;
		case 1:
			lightningImg = mw.chargeLightning1;
			break;
		case 2:
			lightningImg = mw.chargeLightning2;
			break;
		case 3:
			lightningImg = mw.chargeLightning3;
			break;
		case 4:
			lightningImg = mw.chargeLightning4;
			break;
		case 5:
			lightningImg = mw.chargeLightning5;
			break;
		case 6:
			lightningImg = mw.chargeLightning6;
			break;
		case 7:
			lightningImg = mw.chargeLightning7;
			break;
		case 8:
			lightningImg = mw.chargeLightning8;
			break;
		case 9:
			lightningImg = mw.chargeLightning9;
			break;
		default:
			lightningImg = mw.chargeLightning;
		}
		if(lightningCounter == 48) {
			lightningCounter = -1;
		}

		ImageIcon sizedLightning = new ImageIcon(lightningImg.getScaledInstance(xSize, ySize, Image.SCALE_SMOOTH));
		int x1 = offX + width / 2 - sizedLightning.getIconWidth() / 2;
		int y1 = offY + 7 * height / 16 - sizedLightning.getIconHeight() / 2;
		g.drawImage(sizedLightning.getImage(), x1, y1, sizedLightning.getIconWidth(),
				sizedLightning.getIconHeight(), null);
	}

	setForeground(OSVColors.WHITE);
	float yF = height / 12;
	g.setFont(font.deriveFont(yF));

	FontMetrics fm = getFontMetrics(g.getFont());
	int xF = fm.stringWidth(socS.getText());
	int xFPos = offX + width / 2 - xF / 2;
	// int xFPos = x1 / 2 + this.getWidth() / 10 - xF / 2;
	// int yFPos = (int) (this.getHeight() / 3 + y1 / 2 + yF / 4);
	int yFPos = (int) (offY + height - height / 16 - yF / 2);
	g.drawString(socS.getText(), xFPos, yFPos);
}
 
Example 17
Source File: SnakeClient.java    From JavaGame with MIT License 4 votes vote down vote up
/**
 * ���Ʒ���
 * @param g
 */
public void drawScore(Graphics g){
	g.setFont(new Font("Courier New", Font.BOLD, 40));
	g.setColor(Color.WHITE);
	g.drawString("SCORE:"+mySnake.score,700,100);
}
 
Example 18
Source File: MotifBorders.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Paints the border for the specified component with the
 * specified position and size.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(c instanceof JPopupMenu)) {
        return;
    }

    Font origFont = g.getFont();
    Color origColor = g.getColor();
    JPopupMenu popup = (JPopupMenu)c;

    String title = popup.getLabel();
    if (title == null) {
        return;
    }

    g.setFont(font);

    FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
    int         fontHeight = fm.getHeight();
    int         descent = fm.getDescent();
    int         ascent = fm.getAscent();
    Point       textLoc = new Point();
    int         stringWidth = SwingUtilities2.stringWidth(popup, fm,
                                                          title);

    textLoc.y = y + ascent + TEXT_SPACING;
    textLoc.x = x + ((width - stringWidth) / 2);

    g.setColor(background);
    g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
               stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
    g.setColor(foreground);
    SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);

    MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
                                  width, GROOVE_HEIGHT,
                                  shadowColor, highlightColor);

    g.setFont(origFont);
    g.setColor(origColor);
}
 
Example 19
Source File: NimbusViewTabDisplayerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void paintTabContent(Graphics g, int index, String text, int x,
                               int y, int width, int height) {
    // substract lower border
    height--;
    FontMetrics fm = getTxtFontMetrics();
    // setting font already here to compute string width correctly
    g.setFont(getTxtFont());
    int txtWidth = width;
    if (isSelected(index)) {
        Component buttons = getControlButtons();
        if( null != buttons ) {
            Dimension buttonsSize = buttons.getPreferredSize();
            if( width < buttonsSize.width+2*ICON_X_PAD ) {
                buttons.setVisible( false );
            } else {
                buttons.setVisible( true );
                txtWidth = width - (buttonsSize.width + 2*ICON_X_PAD + TXT_X_PAD);
                buttons.setLocation(x + txtWidth +  TXT_X_PAD+ICON_X_PAD, y + (height - buttonsSize.height)/2 + (TXT_Y_PAD / 2));
            }
        }
    } else {
        txtWidth = width - 2 * TXT_X_PAD;
    }
    // draw bump (dragger)
    drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8);
    
    boolean slidedOut = false;
    WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
    if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
        slidedOut = false;
    if( isTabBusy( index ) && !slidedOut ) {
        Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
        txtWidth -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
        busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2);
        x += busyIcon.getIconWidth() + 3;
    }

    // draw text in right color
    Color txtC = UIManager.getColor("TabbedPane.foreground"); //NOI18N
    
    HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
        + TXT_Y_PAD,
        txtWidth, height, getTxtFont(),
        txtC,
        HtmlRenderer.STYLE_TRUNCATE, true);
}
 
Example 20
Source File: RadioButton.java    From DroidUIBuilder with Apache License 2.0 4 votes vote down vote up
@Override
public void paint(Graphics g)
{
	// 绘制背景
	super.paintBackground(g);
	
	int off_x, off_y;

	if (off == null || on == null)
	{
		g.setColor(Color.white);
		g.fillOval(getX() + 2, getY() + 2, 16, 16);

		g.setColor(Color.black);
		g.drawOval(getX() + 2, getY() + 2, 16, 16);

		if ("true".equals(this.getPropertyByAttName("android:checked")
				.getValue()))
		{
			g.fillOval(getX() + 6, getY() + 6, 8, 8);
		}

		off_x = 20;
		off_y = 18;
	}
	else
	{
		Image img = off;
		if ("true".equals(this.getPropertyByAttName("android:checked")
				.getValue()))
		{
			img = on;
		}
		g.drawImage(img, getX(), getY(), null);
		g.setColor(Color.black);

		off_x = img.getWidth(null);
		off_y = img.getHeight(null);
	}

	baseline = (off_y + fontSize) / 2;

	setTextColor(g);
	g.setFont(f);
	// 开启字体绘制反走样
	Utils.setTextAntiAliasing((Graphics2D)g, true);
	g.drawString(text.getStringValue(), getX() + off_x, getY() + baseline - 4);
	// 绘制完成后并闭字体绘制反走样
	Utils.setTextAntiAliasing((Graphics2D)g, false);
}