gpt4 book ai didi

java - 如何删除选项卡 JTabbedPane 中的缩进?

转载 作者:行者123 更新时间:2023-11-30 08:22:33 26 4
gpt4 key购买 nike

如何去除 JTabbedPane 中图标标签周围的缩进?即这个图标在选项卡的全尺寸上是什么?

最佳答案

您可以使用 BasicTabbedPaneUIgetTabInsets() 方法尝试下一个技巧:

import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

public class TestFrame extends JFrame {

public TestFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
pack();
setVisible(true);
}

private void init() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
JTabbedPane pane = new JTabbedPane(JTabbedPane.BOTTOM);
pane.addTab("", new ImageIcon(TestFrame.class.getResource("1111.png")), new JLabel("lbl"));
pane.addTab("test2", new JLabel("lbl2"));
pane.setFocusable(false);
pane.setUI(new BasicTabbedPaneUI() {
@Override
protected Insets getTabInsets(int tabPlacement, int tabIndex) {
return new Insets(0, 0, 0, 0);
}
});
add(pane);
}


public static void main(String... strings) {
new TestFrame();
}

}

enter image description here

也可以试试 calculateTabWidth()calculateTabHeight()

关于java - 如何删除选项卡 JTabbedPane 中的缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24283397/

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