G
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.LinearGradientPaint;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
public class WindowHeadTabbedPaneUI extends BasicTabbedPaneUI {
protected void installDefaults() {
super.installDefaults();
tabAreaInsets.left = 0;
selectedTabPadInsets = new Insets(0, 0, 0, 0);
tabInsets = selectedTabPadInsets;
}
protected int getTabLabelShiftY(int tabPlacement, int tabIndex,
boolean isSelected) {
return 0;
}
protected int getTabLabelShiftX(int tabPlacement, int tabIndex,
boolean isSelected) {
return 2;
}
protected int calculateTabHeight(int tabPlacement, int tabIndex,
int fontHeight) {
int vHeight = fontHeight;
return vHeight + 10;
}
protected int calculateTabWidth(int tabPlacement, int tabIndex,
FontMetrics metrics) {
return 2 + super.calculateTabWidth(tabPlacement, tabIndex, metrics)
+ metrics.getHeight();
}
protected void paintFocusIndicator(Graphics g, int tabPlacement,
Rectangle[] rects, int tabIndex, Rectangle iconRect,
Rectangle textRect, boolean isSelected) {
// Do nothing
}
protected void paintText(Graphics g, int tabPlacement, Font font,
FontMetrics metrics, int tabIndex, String title,
Rectangle textRect, boolean isSelected) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
if (tabIndex == 0) {
tabPane.setForegroundAt(0, Color.white);
} else {
tabPane.setForegroundAt(0, Color.black);
}
super.paintText(g, tabPlacement, font, metrics, tabIndex, title,
textRect, isSelected);
}
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
int x, int y, int w, int h, boolean isSelected) {
x = x + 4;
w = w - 4;
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (tabIndex == 0) {
w = w - 1;
Shape s = new RoundRectangle2D.Double(x, y, w, h, 7, 7);
Shape s2 = new Rectangle2D.Double(x, y + 10, w, h - 10);
Area a = new Area(s);
a.add(new Area(s2));
Paint p = new GradientPaint(x, y, new Color(30, 71, 160), x, y + h,
new Color(36, 78, 166));
g2d.setPaint(p);
g2d.draw(a);
g2d.setColor(new Color(67, 134, 227));
s = new RoundRectangle2D.Double(x + 1, y + 1, w - 2, h - 10, 7, 7);
s2 = new Rectangle2D.Double(x + 1, y + 10, w - 2, h - 11);
a = new Area(s);
a.add(new Area(s2));
g2d.draw(a);
} else {
if (isSelected) {
g2d.setColor(new Color(182, 186, 191));
Shape s = new RoundRectangle2D.Double(x, y, w, h, 7, 7);
Shape s2 = new Rectangle2D.Double(x, y + 10, w, h - 10);
Area a = new Area(s);
a.add(new Area(s2));
g2d.draw(a);
Paint p = new GradientPaint(x - 1, y + 3, new Color(225, 228,
230), x - 1, y + h, new Color(218, 221, 222));
g2d.setPaint(p);
g2d.drawLine(x - 1, y + 3, x - 1, y + h);
g2d.setPaint(p);
g2d.drawLine(x + w + 1, y + 3, x + w + 1, y + h);
g2d.setColor(new Color(195, 198, 202));
g2d.drawLine(x - 1, y + h - 1, x - 1, y + h - 1);
g2d.drawLine(x + w + 1, y + h - 1, x + w + 1, y + h - 1);
}
}
}
protected void paintTabBackground(Graphics g, int tabPlacement,
int tabIndex, int x, int y, int w, int h, boolean isSelected) {
x = x + 4;
w = w - 4;
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (tabIndex == 0) {
Shape s = new RoundRectangle2D.Double(x, y, w, h, 10, 10);
Shape s2 = new Rectangle2D.Double(x, y + 10, w, h - 10);
Area a = new Area(s);
a.add(new Area(s2));
if (isSelected) {
Paint p = new LinearGradientPaint(
new Point2D.Double(x, y),
new Point2D.Double(x, y + h),
new float[] { .0f, 0.5f, 1.0f },
new Color[] { new Color(42, 99, 182),
new Color(39, 94, 177), new Color(58, 141, 232) });
g2d.setPaint(p);
g2d.fill(a);
} else {
Paint p = new LinearGradientPaint(
new Point2D.Double(x, y),
new Point2D.Double(x, y + h),
new float[] { .0f, 0.36f, 1.0f },
new Color[] { new Color(68, 136, 229),
new Color(42, 98, 179), new Color(52, 123, 216) });
g2d.setPaint(p);
g2d.fill(a);
}
} else {
if (isSelected) {
Shape s = new RoundRectangle2D.Double(x, y, w, h, 10, 10);
Shape s2 = new Rectangle2D.Double(x, y + 10, w, h - 10);
Area a = new Area(s);
a.add(new Area(s2));
g2d.setColor(new Color(255, 255, 255));
g2d.fill(a);
}
}
}
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int w = tabPane.getBounds().width;
int h = rects[0].height + 2;
Paint p = new GradientPaint(0, 0, new Color(229, 231, 233), 0, h,
new Color(227, 230, 232));
g2d.setPaint(p);
g2d.fillRect(0, 0, w, h);
super.paintTabArea(g, tabPlacement, selectedIndex);
}
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle selectedRect = selectedIndex < 0 ? null : getTabBounds(
selectedIndex, calcRect);
if (selectedIndex > 0) {
g2d.setColor(new Color(182, 186, 191));
g2d.drawLine(x, y, selectedRect.x + 5, y);
g2d.drawLine(selectedRect.x - 5 + selectedRect.width + 4, y, x + w,
y);
g2d.setColor(new Color(255, 255, 255));
g.drawLine(selectedRect.x + 4, y, selectedRect.x - 4
+ selectedRect.width + 4, y);
} else {
g2d.setColor(new Color(182, 186, 191));
g2d.drawLine(x, y, x + w, y);
}
Rectangle sr = getTabBounds(0, calcRect);
Paint p = new GradientPaint(sr.x + 4, y, new Color(107, 123, 132), sr.x
+ sr.width, y, new Color(182, 186, 191));
g2d.setPaint(p);
g2d.drawLine(sr.x + 4, y, sr.x + sr.width, y);
}
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {
// Do nothing
}
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {
// Do nothing
}
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.white);
g2d.fillRect(x, y + 1, x + w, y + h);
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class Test extends JFrame {
public Test() {
this.setLayout(new BorderLayout());
JTabbedPane tp = new JTabbedPane();
try {
tp.setFont(Font.createFont(Font.TRUETYPE_FONT,
this.getClass().getResourceAsStream("/SEGOEUI.TTF")).deriveFont(13f));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
// tp.setFont(new Font(tp.getFont().getFamily(), Font.PLAIN, 13));
tp.setUI(new WindowHeadTabbedPaneUI());
JPanel pan1 = new JPanel();
pan1.setOpaque(false);
// pan1.setBackground(Color.white);
tp.addTab("Start", pan1);
JPanel pan2 = new JPanel();
pan2.setOpaque(false);
pan2.add(new JLabel("HAll"));
tp.addTab("Eingenschaften", pan2);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(tp, BorderLayout.CENTER);
this.add(p, BorderLayout.CENTER);
this.pack();
this.setSize(500, 300);
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}