BasicTabbedPaneUi
を拡張して、私自身のtabPaneをデザインすることができます。私は、HTMLのテキストに1つの問題がある、タブが選択された後にテキストの色を設定することです。私は、次のようにのorignal方法とほぼ同じコードpaintTextメソッドをオーバーライド:私たちは、タブ用のHTMLテキストを持っている場合はBasicTabbedPaneUIペイントhtmlテキスト
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
Color fg = tabPane.getForegroundAt(tabIndex);
if (isSelected && (fg instanceof UIResource)) {
Color selectedFG = UIManager.getColor(
"TabbedPane.selectedForeground");
if (selectedFG != null) {
fg = selectedFG;
}
}
v.paint(g, textRect);
} else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
Color fg = tabPane.getForegroundAt(tabIndex);
if (isSelected && (fg instanceof UIResource)) {
Color selectedFG = UIManager.getColor(
"TabbedPane.selectedForeground");
if (selectedFG != null) {
fg = selectedFG;
}
}
g.setColor(fg);
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
title, mnemIndex,
textRect.x, textRect.y + metrics.getAscent());
} else { // tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
title, mnemIndex,
textRect.x, textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
title, mnemIndex,
textRect.x - 1, textRect.y + metrics.getAscent() - 1);
}
}
}
を、それvがnullではありません。私が塗りつぶしメソッドで使用されるグラフィックスオブジェクトに色を設定しても、テキストの色は変わりません。 タブのテキストを2行にしたいので、htmlを使用します。 色を変更していただきありがとうございます。
HTML [color](http://www.w3.org/TR/REC-html32)属性を設定するとどうなりますか? – trashgod
これはhtmlタグで直接設定すると機能しますが、タブを選択したときにどのように変更できますか? – xtrem06