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:
Never tried it myself, but from reading the JavaDoc a bit I would try to things:
- Try to use
setMargin(Insets)
- It does not do what you asked for, but it might have the effect you want. - Set the
LayoutManager
usingsetLayout(LayoutManager)
and define the padding on the layout manager to be 0. (Perhaps aGridLayout
is what you need?)
精彩评论