日期:2014-05-20  浏览次数:20773 次

JTabbedPane的两个问题

代码如下:
JTabbedPane  jtabPane = new JTabbedPane( JTabbedPane.BOTTOM );
jtabPane.setBackground( new Color( 202,217,239 ) ) ;//设背景为蓝色
jtabPane.addTab(  "监听用户"  , null , userListPan , "监听用户" ) ;
jtabPane.addTab(  "所有用户"  , null , null , "监听用户" ) ;
jtabPane.addTab(  "用户设置"  , null , null , "监听用户" ) ;

问题1:怎么在页签的标题处加上图片,就像QQ那样每个页签都是图片而不是文字。
问题2:我在代码的第二行将jtabPane的背景设为蓝色怎么还是白色呢?

------解决方案--------------------
API:
public void addTab(String title, Icon icon, Component component, String tip)

or
public void insertTab(String title, Icon icon, Component component, String tip, int index)

------解决方案--------------------
1.void
 
addTab(String title, Icon icon, Component component)
           添加一个由 title 和/或 icon 表示的 component,其任意一个都可以为 null。

2. void
 
setBackgroundAt(int index, Color background)
           将 index 位置的背景色设置为 background,它可以为 null,在这种情况下选项卡的背景色默认为 tabbedpane 的背景色。