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

时间:2014-06-18 10:37:30

标签: java swing user-interface jtabbedpane

如何删除JTabbedPane中图标标签周围的缩进?即这个图标在标签的完整尺寸上是什么?

1 个答案:

答案 0 :(得分:3)

您可以使用getTabInsets()的{​​{1}}方法尝试下一个技巧:

BasicTabbedPaneUI

enter image description here

同时尝试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(); } } calculateTabWidth()