我正在创建自己的自定义
JTabbedPane
对象,使用一个简单的继承了JTabbedPane
的小类。我已经完成了其中的很大部分工作,但最近发现一个问题,即选项卡标题文本不会自动居中。而我想要它居中。下面是它的样子:
JTabbedArea
的扩展,就像这样:private static final long serialVersionUID = 1L;
private String name;
private final int width = 150, height = 50;
public ColoredTabs(String paneName, int tabPlacement, String[] names, Color[] colors, JComponent[] components){
super(tabPlacement);
this.name = paneName;
if(names.length != components.length || names.length != colors.length || components.length != colors.length){
throw new IllegalArgumentException("The arguments for COMPONENTS, COLORS, and NAMES do not match up for '"+this.name+"'...");
}
setFont(Resources.getFont());
setBackground(Color.YELLOW);
for(int i = 0; i < names.length; i++){
addTab(names[i], components[i]);
setBackgroundAt(i, colors[i]);
setIconAt(i, new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)));
}
}
我制作BufferedImage的原因是为了拉伸Tab的区域,对于图标,也许有一种方法可以将文本居中显示在BufferedImage上,有什么想法吗?