3
我創建了我自己的自定義JTabbedPane
對象,其中包含一個簡單的小類,用於擴展JTabbedPane
。我已經完成了相當多的工作,但最近發現了一個問題,即選項卡的標題文本不會自動對齊到選項卡的中心。我希望它。這裏是什麼樣子:Java 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的區域,對於ICON,也許有一種方法可以將文本置於BufferedImage的中心,有什麼想法?
是啊,你說得對。最好的方法是將JLabel放入該區域,現在我只是使用JLabel來拉伸Tab的區域,謝謝。 – tanishalfelven