gpt4 book ai didi

java - 有什么方法可以使图像适合选项卡组件

转载 作者:行者123 更新时间:2023-11-29 05:38:48 25 4
gpt4 key购买 nike

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

enter image description here

我试过这段代码

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

我也试过这个作为解决方案但没有奏效。

JLabel label = new JLabel(icon);
label.setBackground(Color.BLUE);
tabbedPaneProductDetail.setTabComponentAt(1,label);

最佳答案

您可以尝试使用 UIManager。在开始创建组件之前,在程序的开头添加以下内容:

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

当然不是所有的 LAF 都支持这个选项。参见 UIManager Defaults获取更多信息。

关于java - 有什么方法可以使图像适合选项卡组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18468169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com