Java JTabbedPane align Center header text

I create my own custom object JTabbedPanewith a simple small class that extends JTabbedPane. I got quite a lot of this, but I recently discovered a problem in that the title text for the tab does not automatically center the tab. And I want this. Here's what it looks like:

Just imagine that the tabs aren't aligned to the center

As I said, this is just an extension JTabbedArea, for example:

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)));

    }
}

The reason I am facing the problem of creating a BufferedImage is to stretch the Tab area, for ICON, maybe there is a way to focus the text on the BufferedImage, any ideas?

+3
source share
1 answer

tabbedPane , jTabbedPane, - :

//Create new label to be used as a tab name
JLabel tabLabel = new JLabel("Tab", JLabel.CENTER);
//add new label at set location
jTabbedPane.setTabComponentAt(0, tabLabel);

, , , .

: : JTabbedPane Nimbus Look and Feel

+3

All Articles