在此JTabbedPane
屏幕截图中
我正在使用Netbeans的DnD,我一直在修补它只是为了在标签之间放置空格。到目前为止,我仍然无法得到我想要的东西。
有办法吗?
答案 0 :(得分:4)
我不确定其他方式,但我认为您必须在TabbedPaneUI
上安装自己的自定义JTabbedPane
。
示例:
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.basic.*;
public class JTabbedPaneWithSpaces implements Runnable
{
public static void main(String[] args) throws Exception
{
SwingUtilities.invokeLater(new JTabbedPaneWithSpaces());
}
public void run()
{
JTabbedPane pane = new JTabbedPane();
pane.setUI(new SpacedTabbedPaneUI());
pane.addTab("One", new JPanel());
pane.addTab("Two", new JPanel());
pane.addTab("Threeeeeee", new JPanel());
pane.addTab("Four", new JPanel());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(pane);
frame.setSize(500, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public class SpacedTabbedPaneUI extends BasicTabbedPaneUI
{
@Override
protected LayoutManager createLayoutManager()
{
return new BasicTabbedPaneUI.TabbedPaneLayout()
{
@Override
protected void calculateTabRects(int tabPlacement, int tabCount)
{
final int spacer = 20; // should be non-negative
final int indent = 4;
super.calculateTabRects(tabPlacement,tabCount);
for (int i = 0; i < rects.length; i++)
{
rects[i].x += i * spacer + indent;
}
}
};
}
}
}