/** Constructs the <tt>SearchPanel</tt>. */ private void init() { String searchString = GuiActivator.getResources().getI18NString("service.gui.SEARCH"); JLabel searchLabel = new JLabel(searchString + ": "); searchButton = new JButton(searchString, new ImageIcon(ImageLoader.getImage(ImageLoader.SEARCH_ICON))); this.searchTextField.getDocument().addDocumentListener(this); this.add(searchLabel, BorderLayout.WEST); this.add(searchTextField, BorderLayout.CENTER); searchButton.setName("search"); searchButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.SEARCH")); searchButton.addActionListener(this); this.historyWindow.getRootPane().setDefaultButton(searchButton); this.add(searchButton, BorderLayout.EAST); }
/** * Creates the appropriate object to represent each of the objects in <code>buttons</code> and * adds it to <code>container</code>. This differs from addMessageComponents in that it will * recurse on <code>buttons</code> and that if button is not a Component it will create an * instance of JButton. */ protected void addButtonComponents(Container container, Object[] buttons, int initialIndex) { if (buttons != null && buttons.length > 0) { boolean sizeButtonsToSame = getSizeButtonsToSameWidth(); boolean createdAll = true; int numButtons = buttons.length; JButton[] createdButtons = null; int maxWidth = 0; if (sizeButtonsToSame) { createdButtons = new JButton[numButtons]; } for (int counter = 0; counter < numButtons; counter++) { Object button = buttons[counter]; Component newComponent; if (button instanceof Component) { createdAll = false; newComponent = (Component) button; container.add(newComponent); hasCustomComponents = true; } else { JButton aButton; if (button instanceof ButtonFactory) { aButton = ((ButtonFactory) button).createButton(); } else if (button instanceof Icon) aButton = new JButton((Icon) button); else aButton = new JButton(button.toString()); aButton.setName("OptionPane.button"); aButton.setMultiClickThreshhold( DefaultLookup.getInt(optionPane, this, "OptionPane.buttonClickThreshhold", 0)); configureButton(aButton); container.add(aButton); ActionListener buttonListener = createButtonActionListener(counter); if (buttonListener != null) { aButton.addActionListener(buttonListener); } newComponent = aButton; } if (sizeButtonsToSame && createdAll && (newComponent instanceof JButton)) { createdButtons[counter] = (JButton) newComponent; maxWidth = Math.max(maxWidth, newComponent.getMinimumSize().width); } if (counter == initialIndex) { initialFocusComponent = newComponent; if (initialFocusComponent instanceof JButton) { JButton defaultB = (JButton) initialFocusComponent; defaultB.addHierarchyListener( new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) { JButton defaultButton = (JButton) e.getComponent(); JRootPane root = SwingUtilities.getRootPane(defaultButton); if (root != null) { root.setDefaultButton(defaultButton); } } } }); } } } ((ButtonAreaLayout) container.getLayout()) .setSyncAllWidths((sizeButtonsToSame && createdAll)); /* Set the padding, windows seems to use 8 if <= 2 components, otherwise 4 is used. It may actually just be the size of the buttons is always the same, not sure. */ if (DefaultLookup.getBoolean(optionPane, this, "OptionPane.setButtonMargin", true) && sizeButtonsToSame && createdAll) { JButton aButton; int padSize; padSize = (numButtons <= 2 ? 8 : 4); for (int counter = 0; counter < numButtons; counter++) { aButton = createdButtons[counter]; aButton.setMargin(new Insets(2, padSize, 2, padSize)); } } } }