public void setShowNames(boolean b) { if (shownames == b) return; shownames = b; Iterator it = buttons.keySet().iterator(); while (it.hasNext()) { String command = (String) it.next(); JButton button = (JButton) buttons.get(command); button.setText((shownames) ? command : ""); button.setToolTipText((!shownames) ? command : ""); } setButtonsSize(); }
public void setIcon(String command, ImageIcon icon) { JButton b = (JButton) buttons.get(command); if (b != null) { b.setIcon(icon); b.revalidate(); setButtonsSize(); } }
protected void setButtonsSize() { int nMaxWidth = 0, nMaxHeight = 0; Dimension objSize; Iterator objIterator = buttons.values().iterator(); while (objIterator.hasNext()) { JButton objButton = (JButton) objIterator.next(); objButton.setPreferredSize(null); objSize = objButton.getPreferredSize(); nMaxWidth = Math.max(nMaxWidth, objSize.width); nMaxHeight = Math.max(nMaxHeight, objSize.height); } objSize = new Dimension(nMaxWidth, nMaxHeight); d = objSize; objIterator = buttons.values().iterator(); while (objIterator.hasNext()) { ((JButton) objIterator.next()).setPreferredSize(objSize); } }
public void setCommands(String[] names) { panel.removeAll(); panel.add(Box.createHorizontalGlue()); for (int i = 0; i < names.length; i++) { JButton b = new XButton(""); if (shownames) b.setText(names[i]); else b.setToolTipText(names[i]); b.setActionCommand(names[i]); b.addActionListener(this); b.setMargin(new InsetsUIResource(0, 6, 0, 6)); panel.add(b); if (i < names.length - 1) { if (isHorisontal()) { panel.add(Box.createHorizontalStrut(9)); } else { panel.add(Box.createVerticalStrut(5)); } } buttons.put(names[i], b); } setButtonsSize(); panel.validate(); }
public void setEnabled(String command, boolean enabled) { JButton b = (JButton) buttons.get(command); if (b != null) b.setEnabled(enabled); }