Is there any way to fit an image in a tab component
Asked Answered
A

2

1

I'm adding icons to tabs but i want the ImageIcon fits all the 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 not worked.

JLabel label = new JLabel(icon);
label.setBackground(Color.BLUE);
tabbedPaneProductDetail.setTabComponentAt(1,label);
Avalos answered 27/8, 2013 at 14:23 Comment(0)
A
1

I found a solution, i don't know if it's the proper one, thanks to @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));
Avalos answered 27/8, 2013 at 15:12 Comment(0)
K
2

You can try playing with the UIManager. Add the following at the start of your program before you start creating component:

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

Of course not all LAF's may support this option. See UIManager Defaults for more information.

Kerrikerrie answered 27/8, 2013 at 14:39 Comment(3)
Thanks camickr ,don't work cause nimbus doesn't have that property, i found another solution but i don't know if it's the proper one, check my answerAvalos
UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab.contentMargins", new Insets(0, 0, 0, 0)); i found this property in nimbus that helpsAvalos
TabbedPane:TabbedPaneTabArea.contentMarginsAvalos
A
1

I found a solution, i don't know if it's the proper one, thanks to @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));
Avalos answered 27/8, 2013 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.