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

booleanisToolBarButton(JComponent c)
Returns true if the specified widget is in a toolbar.
return c.getParent() instanceof JToolBar;
JButtonmakeToolButton(URL iconURL, String cmd, String tooltip, String alt, ActionListener listener)
make Tool Button
JButton button = new JButton();
button.setActionCommand(cmd);
button.setToolTipText(tooltip);
button.addActionListener(listener);
if (iconURL != null) {
    button.setIcon(new ImageIcon(iconURL, alt));
} else { 
    button.setText(alt);
...
voidresizeToolBarButtons(JComponent toolbar)
Make the size of all toolbar buttons uniform.
Component[] components = toolbar.getComponents();
int len = components.length;
Dimension max_dim = new Dimension(0, 0);
for (int i = 0; i < len; i++) {
    if (!(components[i] instanceof JButton))
        continue;
    Dimension size = components[i].getPreferredSize();
    if (size.width > max_dim.width)
...
JToolBarsearchFakeToolBarRecursive(Container c)
search Fake Tool Bar Recursive
if (c instanceof JToolBar) {
    return (JToolBar) c;
if (c.getComponents().length > 0) {
    Component[] comps = c.getComponents();
    for (int i = 0; i < comps.length; i++) {
        JToolBar f = searchFakeToolBarRecursive((Container) comps[i]);
        if (f != null) {
...
voidsetToolIcons(AbstractButton b, Icon[] icons)
Change the Icons of an AbstractButton (JButton or JToggleButton).
b.setIcon(icons[0]);
b.setSelectedIcon(icons[1]);
b.setPressedIcon(icons[3]);
b.setDisabledIcon(icons[2]);
voidsetToolIcons(AbstractButton b, Icon[] icons)
Change the Icons of an AbstractButton (JButton or JToggleButton).
b.setIcon(icons[0]);
b.setSelectedIcon(icons[1]);
b.setPressedIcon(icons[3]);
b.setDisabledIcon(icons[2]);
Insets defInsets = b.getInsets();
voidshowTextOnToolbar(javax.swing.JToolBar t, boolean show)
This method shows/hides the text of the buttons on 't' according to the value of 'show'.
for (int i = t.getComponentCount() - 1; i >= 0; --i) {
    if (t.getComponent(i) instanceof javax.swing.AbstractButton) {
        javax.swing.AbstractButton button = (javax.swing.AbstractButton) t.getComponent(i);
        Object hide = button.getClientProperty("hideActionText");
        javax.swing.Action a = button.getAction();
        try {
            Method m = AbstractButton.class.getMethod("setHideActionText", Boolean.TYPE);
            m.invoke(button, !show);
...
voidstyleToolBarButton(final AbstractButton btn, final Font font, final boolean addPadding)
style Tool Bar Button
btn.setFont(font);
btn.setBorder(null);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
btn.setFocusPainted(false);
btn.setFocusable(false);
if (addPadding) {
    final Dimension d = btn.getPreferredSize();
...