开发者

How to remove gap between controls in JToolBar?

How to remove gap between controls in JToolBar? I want to have no free space between control开发者_StackOverflows in JToolBar.

EDIT: I was wrong. There is no free space. The problem is caused by JButton (situated in JToolBar) with icon only. It has some extra margins around the icon. How to remove them?


The code at http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JToolBar.html explains it with example code:

public class ToolBarButton extends JButton {
  private static final Insets margins = new Insets(0, 0, 0, 0);

  public ToolBarButton(Icon icon) {
     super(icon);
     setMargin(margins);
     setVerticalTextPosition(BOTTOM);
     setHorizontalTextPosition(CENTER);
  }
  // ...

Screen shot:

How to remove gap between controls in JToolBar?


Never tried it myself, but from reading the JavaDoc a bit I would try to things:

  1. Try to use setMargin(Insets) - It does not do what you asked for, but it might have the effect you want.
  2. Set the LayoutManager using setLayout(LayoutManager) and define the padding on the layout manager to be 0. (Perhaps a GridLayout is what you need?)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜