Here you can find the source of paintBandTitle(Graphics g, Rectangle titleRectangle, String title, boolean isUnderMouse, boolean hasExpandIcon)
public static void paintBandTitle(Graphics g, Rectangle titleRectangle, String title, boolean isUnderMouse, boolean hasExpandIcon)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 UCLA Medical Imaging Informatics Group * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html ******************************************************************************/ import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.Shape; import javax.swing.UIManager; import javax.swing.plaf.basic.BasicGraphicsUtils; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; public class Main { private static final Color FOREGROUND = UIManager .getColor("RibbonBand.foreground"); private static final Font BAND_FONT = UIManager .getFont("RibbonBand.font"); public static void paintBandTitle(Graphics g, Rectangle titleRectangle, String title, boolean isUnderMouse, boolean hasExpandIcon) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); Shape s = new RoundRectangle2D.Double(titleRectangle.x, titleRectangle.y, titleRectangle.width, titleRectangle.height, 8, 8); GradientPaint gp1 = new GradientPaint(0, titleRectangle.y + titleRectangle.height / 2, new Color(75, 75, 75), 0, titleRectangle.y + titleRectangle.height, new Color(100, 100, 100));//from w w w .j av a 2 s . c o m g2.setPaint(gp1); g2.fill(s); GradientPaint gp2 = new GradientPaint(0, titleRectangle.y, new Color(140, 140, 160), 0, titleRectangle.y + titleRectangle.height / 2, new Color(105, 105, 105)); g2.setPaint(gp2); g2.fill(new Rectangle2D.Double(titleRectangle.x, titleRectangle.y, titleRectangle.width, titleRectangle.height / 2 - 1)); g2.setFont(BAND_FONT); int y = titleRectangle.y + (titleRectangle.height + g2.getFontMetrics().getAscent()) / 2; g2.setBackground(Color.black); g2.setColor(FOREGROUND); if (title != null) { Rectangle2D titleBounds = g2.getFontMetrics().getStringBounds( title, g2); double tmpX = ((titleRectangle.width - titleBounds.getWidth()) / 2); double xCoord = (hasExpandIcon) ? (((titleRectangle.x + tmpX + titleBounds.getWidth() + 5) > (titleRectangle.x + titleRectangle.width - 10)) ? 3 : tmpX) : tmpX; BasicGraphicsUtils.drawString(g2, title, 0, (int) (titleRectangle.x + xCoord), y - 2); } g2.dispose(); } }