List of usage examples for javax.swing JButton getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JPanel createButtonsPanel(Action[] actions, final DialogWindow dialog) { JPanel buttonsPanel = new JPanel(); boolean hasPrimaryAction = false; for (final Action action : actions) { JButton button = new JButton(action.getCaption()); String icon = action.getIcon(); if (icon != null) { button.setIcon(AppBeans.get(IconResolver.class).getIconResource(icon)); }// ww w .ja v a 2 s . com final DialogActionHandler dialogActionHandler = new DialogActionHandler(dialog, action); button.addActionListener(dialogActionHandler); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); userActionsLog.trace("Button (name = {}, text = {}) was clicked in dialog", b.getName(), b.getText()); } }); if (actions.length == 1) { dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { dialogActionHandler.onClose(); } }); } button.setPreferredSize( new Dimension(button.getPreferredSize().width, DesktopComponentsHelper.BUTTON_HEIGHT)); button.setMaximumSize(new Dimension(Integer.MAX_VALUE, DesktopComponentsHelper.BUTTON_HEIGHT)); if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) { hasPrimaryAction = true; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { button.requestFocus(); } }); } buttonsPanel.add(button); } if (!hasPrimaryAction && actions.length > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { buttonsPanel.getComponent(0).requestFocus(); } }); } return buttonsPanel; }