有没有办法在选项卡组件中放置图像 [英] Is there any way to fit an image in a tab component

查看:127
本文介绍了有没有办法在选项卡组件中放置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向标签添加图标,但我希望ImageIcon适合所有tabComponent。

I'm adding icons to tabs but i want the ImageIcon fits all the tabComponent.

我试过这段代码

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


推荐答案

我找到了一个解决方案,我不知道是否这是正确的,感谢@camickr

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

});

更新

我找到另一个解决方案设置此属性

I found another solution setting this property

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

这篇关于有没有办法在选项卡组件中放置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆