Take the 2-minute tour ×

hello i am using the nimbus look-and-feel and have a tabbedpane with an icon and text. now the icon appears on the right side of the text, while i would like to have it on the left side.

also i would like to add some spacing between the icon and the text.


share|improve this question

1 Answer 1

up vote 15 down vote accepted

You need to set the tab component yourself; which governs how the tab title is rendered.

// Create tabbed pane and add tabs.
JTabbedPane tabbedPane = ...

// Create bespoke component for rendering the tab.
JLabel lbl = new JLabel("Hello, World");
Icon icon = new ImageIcon(getClass().getResource("/foo/bar/hello.jpg"));

// Add some spacing between text and icon, and position text to the RHS.

// Assign bespoke tab component for first tab.
tabbedPane.setTabComponentAt(0, lbl);

Obviously you could encapsulate this in a utility method:

private void addTab(JTabbedPane tabbedPane, Component tab, String title, Icon icon) {

  JLabel lbl = ... // Create bespoke label for rendering tab title.

  tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, lbl);
share|improve this answer
i was using this code to add (component,string,icon and tooltip) to the tab pane.addTab("Name of Tab", new ImageIcon("resources\\1.png"), mainPanel," tooltip text"); now i want the same (the text to appear on right and icon on left) i tried the same u specified in ur comment above ...and i got exception in my code ...please help –  Gagan93 Nov 5 '13 at 8:10
@Gagan93: Please can you post this as a separate question; without seeing the exception I'm not sure I can help. –  Adamski Nov 5 '13 at 8:35
ok, i wasn't posting in fear of getting downvoted, i m posting a different question within 2 minues with my problem...please provide a solution –  Gagan93 Nov 5 '13 at 10:45

Your Answer


