Java Utililty Methods JToolBar

List of utility methods to do JToolBar

Description

The list of methods to do JToolBar are organized into topic(s).

Method

JToolBarcreateToolbar()
create Toolbar
JToolBar toolbar = new JToolBar();
toolbar.setFloatable(false);
JButton button = null;
button = makeNavigationButton(CLOSE, "Close the expression window", "Close Window");
toolbar.add(button);
button = makeNavigationButton(EXIT, "Exit the program", "Exit Program");
toolbar.add(button);
return toolbar;
...
voidfixButton(AbstractButton button, String toolTip)
fix Button
button.setFocusable(false);
button.setMargin(ZERO_INSETS);
button.setToolTipText(toolTip);
voidfloatToolBar(JToolBar tb, Point p)
float Tool Bar
ToolBarUI tbUI = tb.getUI();
if (tbUI instanceof BasicToolBarUI)
    ((BasicToolBarUI) tbUI).setFloating(false, p);
voidformatToolBar(JToolBar toolbar, int style)
format Tool Bar
Component[] comps = toolbar.getComponents();
for (int count = 0; count < comps.length; count++) {
    if (comps[count] instanceof AbstractButton) {
        if (style == ICON_ONLY) {
            ((AbstractButton) comps[count]).setText(null);
        } else if (style == TEXT_ONLY) {
            ((AbstractButton) comps[count]).setIcon(null);
AbstractButtongetToolbarButton(JToolBar toolbar, Action action)
Find the JButton in the toolbar that is associated with the provided action
return getMenuItem(toolbar, action);
JComponentgetToolBarFill(int orientation)
get Tool Bar Fill
Dimension dim = null;
if (orientation == SwingConstants.HORIZONTAL) {
    dim = new Dimension(2, 1);
} else {
    dim = new Dimension(1, 2);
return new Box.Filler(dim, dim, dim);
intgetToolbarOrientation(String location)
Returns a toolbar orientation based on its location.
return (location.equalsIgnoreCase(BorderLayout.NORTH) || location.equalsIgnoreCase(BorderLayout.SOUTH))
        ? JToolBar.HORIZONTAL
        : JToolBar.VERTICAL;
voidhideChildButtonsWithTooltip(Container parent, String tooltip)
Find button by tooltip
for (Component component : parent.getComponents()) {
    if (component instanceof AbstractButton
            && tooltip.equals(((AbstractButton) component).getToolTipText())) {
        component.setVisible(false); 
    } else if (component instanceof Container) {
        hideChildButtonsWithTooltip((Container) component, tooltip);
voidinitIconButton(AbstractButton button, String toolTip)
Inits the icon button.
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setToolTipText(toolTip);
booleanisToolBarButton(JComponent c)
is Tool Bar Button
return (c.getParent() instanceof JToolBar);