Is there a way to put an image in a tab component

I am adding icons to the tabs, but I want the ImageIcon to match all tabComponent.

enter image description here

I tried this code

ImageIcon icon = new ImageIcon("images/itemtexto-off.png"); Image img = icon.getImage() ; Image newimg = img.getScaledInstance( 50, 25, java.awt.Image.SCALE_DEFAULT ) ; icon = new ImageIcon( newimg ); tabbedPaneProductDetail.setIconAt(0, icon); 

Also I tried this as a solution, but did not work.

 JLabel label = new JLabel(icon); label.setBackground(Color.BLUE); tabbedPaneProductDetail.setTabComponentAt(1,label); 
+1
java swing nimbus jtabbedpane
source share
2 answers

I found a solution, I don’t know if it is right, thanks @camickr

 tabbedPane.setUI(new SynthTabbedPaneUI(){ Insets insets =new Insets(0, 0, 0, 0); @Override protected Insets getTabInsets(int tabPlacement, int tabIndex){ return insets; } }); 

enter image description here

UPDATE

I found another solution setting this property

 UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab.contentMargins", new Insets(0, 0, 0, 0)); 
+1
source share

You can try playing with UIManager. Add the following to the beginning of your program before you begin creating the component:

 UIManager.put("TabbedPane.tabInsets", new Insets(0, 0, 0, 0)); 

Of course, not all LAFs can support this option. See the default UIManager for more details.

+2
source share

All Articles