我爲我的JTabbedPane創建了一個自定義LaF,唯一的問題是它只顯示標籤,而不是文本,請幫助,我已經嘗試了一切!自定義JTabbedPane LaF不顯示文本
package com.jama.lyricist.ui;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
public class AdvancedTabbedPaneUI extends BasicTabbedPaneUI{
@Override
protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) {
Color savedColor = g.getColor();
g.setColor(new Color(238,238,238));
g.fillRect(rects[tabIndex].x, rects[tabIndex].y,
rects[tabIndex].width, rects[tabIndex].height);
g.setColor(new Color(153, 153, 153));
g.drawRect(rects[tabIndex].x, rects[tabIndex].y,
rects[tabIndex].width, rects[tabIndex].height);
g.setColor(new Color(102,102,102));
g.setColor(savedColor);
}
private final Insets borderInsets = new Insets(0, 0, 0, 0);
@Override
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
}
@Override
protected Insets getContentBorderInsets(int tabPlacement) {
return borderInsets;
}
@Override
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {
super.paintContentBorderTopEdge(g, tabPlacement, -1, x, y, w, h);
}
}
它輸出這樣的:Output
你在哪兒畫標籤標題?我想你需要在'paintTab'方法的某個地方拋出'paintText',如[這裏]所示(http://kickjava.com/src/javax/swing/plaf/basic/BasicTabbedPaneUI.java.htm#576 ) –