JTabbedPane: black text on black background when windows is on HC#2 mode.
Hi,
I have an accessibility issues with JTabbedPane.
OS: windows xp
JDK: 1.5.0_11
Precondition: Set you OS to High Contrast #2 mode
Problem: Set the UI to Windows L&F, If u disable one tab by using JTabbedPane.setEnabledAt( index,false);
, you will get black text on black background. I suppose that this is a Java bug. Does anyone has any idea about this?
# 1
in class BasicTabbedPaneUI, which decide the UI of JTabbedPane, there is a method
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
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
//PAY ATTENTION TO HERE
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);
}
}
}
In HC2 mode, the background is black. In this UI class, when the tab is disabled, it will set text color to brighter and darker of background color,
so text is black , so you can not see the text.