从JTabbedPane中删除蓝色

时间:2011-03-04 00:41:00

标签: java swing

这是我第一次使用JTabbedPane。默认外观似乎在选项卡上和组件本身周围显示蓝色边框边框。如何禁用该效果?

2 个答案:

答案 0 :(得分:3)

嗯,通过将LookAndFeel设置为SystemLookAndFeel(或任何其他lookandfeel),您可以轻松快捷地删除此“效果”:

    UIManager.setLookAndFeel(
        UIManager.getSystemLookAndFeelClassName());

请阅读这篇文章,以便了解有关该主题的更多信息:http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

答案 1 :(得分:0)

使用" UIManager"

更改外观和感觉
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled+MouseOver].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled+Pressed].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+MouseOver+Selected].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+Pressed+Selected].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+Selected].backgroundPainter", new BackgroundPainter(Color.GRAY));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Pressed+Selected].backgroundPainter", new BackgroundPainter(Color.white));
            UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Selected].backgroundPainter", new BackgroundPainter(Color.white));

BackgroundPainter类

public class BackgroundPainter implements Painter<JComponent> {

private Color color = null;

BackgroundPainter(Color c) {
    color = c;
}

@Override
public void paint(Graphics2D g, JComponent object, int width, int height) {
    if (color != null) {
        g.setColor(color);
        g.fillRect(0, 0, width - 1, height - 1);
    }
}

}