List of usage examples for javax.swing JButton setSize
public void setSize(Dimension d)
From source file:Main.java
/** * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any. *//*from www . ja v a 2 s .c om*/ public static void tieButtonSizes(List<JButton> buttons) { int maxWidth = 0; int maxHeight = 0; for (JButton button : buttons) { Dimension buttonSize = button.getPreferredSize(); maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth); maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight); } Dimension maxButtonSize = new Dimension(maxWidth, maxHeight); for (JButton button : buttons) { // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size. button.setPreferredSize(maxButtonSize); button.setMinimumSize(maxButtonSize); button.setMaximumSize(maxButtonSize); button.setSize(maxButtonSize); } }
From source file:net.sf.taverna.t2.activities.rshell.views.RshellConfigurationPanel.java
private Component createSettingsPanel() { JPanel settingsPanel = new JPanel(new GridBagLayout()); GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.weightx = 0.0;//from w ww . ja v a 2s .c o m labelConstraints.gridx = 0; labelConstraints.gridy = 0; labelConstraints.fill = GridBagConstraints.NONE; labelConstraints.anchor = GridBagConstraints.LINE_START; GridBagConstraints fieldConstraints = new GridBagConstraints(); fieldConstraints.weightx = 1.0; fieldConstraints.gridx = 1; fieldConstraints.gridy = 0; fieldConstraints.fill = GridBagConstraints.HORIZONTAL; GridBagConstraints buttonConstraints = new GridBagConstraints(); buttonConstraints.weightx = 1.0; buttonConstraints.gridx = 1; buttonConstraints.gridy = 2; buttonConstraints.fill = GridBagConstraints.NONE; buttonConstraints.anchor = GridBagConstraints.WEST; Dimension dimension = new Dimension(0, 0); hostnameField = new JTextField(); JLabel hostnameLabel = new JLabel("Hostname"); hostnameField.setSize(dimension); hostnameLabel.setSize(dimension); hostnameLabel.setLabelFor(hostnameField); JsonNode connectionSettings = getJson().path("connection"); hostnameField.setText(connectionSettings.path("hostname").asText()); portField = new JTextField(); JLabel portLabel = new JLabel("Port"); portField.setSize(dimension); portLabel.setSize(dimension); portLabel.setLabelFor(portField); portField.setText( Integer.toString(connectionSettings.path("port").asInt(RshellTemplateService.DEFAULT_PORT))); // "Set username and password" button ActionListener usernamePasswordListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (credManagerUI == null) { credManagerUI = new CredentialManagerUI(credentialManager); } credManagerUI.newPasswordForService( URI.create("rserve://" + hostnameField.getText() + ":" + portField.getText())); // this is used as a key for the service in Credential Manager } }; JButton setHttpUsernamePasswordButton = new JButton("Set username and password"); setHttpUsernamePasswordButton.setSize(dimension); setHttpUsernamePasswordButton.addActionListener(usernamePasswordListener); keepSessionAliveCheckBox = new JCheckBox("Keep Session Alive"); keepSessionAliveCheckBox.setSelected(connectionSettings.path("keepSessionAlive") .asBoolean(RshellTemplateService.DEFAULT_KEEP_SESSION_ALIVE)); settingsPanel.add(hostnameLabel, labelConstraints); labelConstraints.gridy++; settingsPanel.add(hostnameField, fieldConstraints); fieldConstraints.gridy++; settingsPanel.add(portLabel, labelConstraints); labelConstraints.gridy++; settingsPanel.add(portField, fieldConstraints); fieldConstraints.gridy++; settingsPanel.add(setHttpUsernamePasswordButton, buttonConstraints); buttonConstraints.gridy++; fieldConstraints.gridy++; settingsPanel.add(keepSessionAliveCheckBox, fieldConstraints); fieldConstraints.gridy++; return settingsPanel; }
From source file:inet.CalculationNetworkEditor.visual.view.EditorPane.java
private void addContentToStackingEdgePanel(JPanel rightPanel, E e, Collection<E> allPhysicalCol) { //caption/*from w ww. ja v a2 s . c o m*/ JLabel caption = new JLabel("Map: " + e); caption.setSize(new Dimension(180, 20)); caption.setPreferredSize(new Dimension(180, 20)); rightPanel.add(caption, BorderLayout.NORTH); //to JPanel toPanel = new JPanel(); toPanel.setLayout(new BorderLayout()); rightPanel.add(toPanel, BorderLayout.CENTER); JLabel to = new JLabel("To:"); to.setSize(new Dimension(180, 20)); to.setPreferredSize(new Dimension(180, 20)); toPanel.add(to, BorderLayout.NORTH); // buttons edge button panel JPanel buttonsEdgePanel = new JPanel(); buttonsEdgePanel.setLayout(new BorderLayout()); toPanel.add(buttonsEdgePanel, BorderLayout.CENTER); // path listPanel //JPanel pathListPanel = new JPanel(); //pathListPanel.setLayout(new BorderLayout); defaultListModel = new DefaultListModel<E>(); pathList = new JList<E>(defaultListModel); pathList.setSize(180, 100); pathList.setPreferredSize(new Dimension(180, 100)); buttonsEdgePanel.add(pathList, BorderLayout.CENTER); // add remove edge button panel JPanel addRemoveEdgePanel = new JPanel(); addRemoveEdgePanel.setLayout(new BorderLayout()); buttonsEdgePanel.add(addRemoveEdgePanel, BorderLayout.SOUTH); // add Button JButton addButton = new JButton("add"); addRemoveEdgePanel.add(addButton, BorderLayout.LINE_START); addButton.addActionListener(editingPanelsListener); addButton.setSize(new Dimension(70, 20)); addButton.setPreferredSize(new Dimension(70, 20)); // remove Button JButton removeButton = new JButton("remove"); addRemoveEdgePanel.add(removeButton, BorderLayout.LINE_END); removeButton.addActionListener(editingPanelsListener); removeButton.setSize(new Dimension(90, 20)); removeButton.setPreferredSize(new Dimension(90, 20)); // add drop done box with all physical edges allPhysicalEdgeJCB = new JComboBox<E>(); for (E edge : allPhysicalCol) { if (!defaultListModel.contains(edge)) { allPhysicalEdgeJCB.addItem(edge); } } toPanel.add(allPhysicalEdgeJCB, BorderLayout.SOUTH); allPhysicalEdgeJCB.setSize(new Dimension(180, 30)); allPhysicalEdgeJCB.setPreferredSize(new Dimension(180, 30)); allPhysicalEdgeJCB.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); // JButton stack JButton stack = new JButton("map"); stack.addActionListener(editingPanelsListener); rightPanel.add(stack, BorderLayout.SOUTH); }
From source file:fxts.stations.util.preferences.EditAction.java
public void actionPerformed(ActionEvent aEvent) { JButton okButton = UIManager.getInst().createButton(); JButton cancelButton = UIManager.getInst().createButton(); final JDialog dialog = new JDialog(mEditorPanel.getParentDialog()); dialog.setTitle(mEditorPanel.getTitle()); JPanel editPanel = new JPanel(); JPanel buttonPanel = new JPanel(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); //mainPanel.setLayout(new SideLayout()); //sets button panel buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); okButton.setText(mResMan.getString("IDS_OK_BUTTON")); //okButton.setPreferredSize(new Dimension(80, 27)); GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0;//from ww w .j a v a 2 s . com sideConstraints.gridy = 0; ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(okButton, sideConstraints); cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON")); //cancelButton.setPreferredSize(new Dimension(80, 27)); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 1; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(cancelButton, sideConstraints); //adds button panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0; sideConstraints.gridy = 1; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 1.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(buttonPanel, sideConstraints); //sets edit panel final IEditor editor = mType.getEditor(); editor.setValue(mValue); editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); Component editComp = editor.getComponent(); //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4. if (editComp instanceof FontChooser) { FontChooser fc = (FontChooser) editComp; fc.setNextFocusedComp(okButton); } editPanel.add(editComp, sideConstraints); //adds editor panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.gridx = 0; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(editPanel, sideConstraints); //adds main panel dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout()); //dialog.getContentPane().setLayout(new SideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.fill = GridBagConstraints.BOTH; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); dialog.getContentPane().add(mainPanel, sideConstraints); //adds listeners to buttons okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (editor.getValue().equals(mValue)) { // } else { mValue = editor.getValue(); mEditorPanel.setValue(mValue); mEditorPanel.refreshControls(); mEditorPanel.setValueChanged(true); } dialog.setVisible(false); dialog.dispose(); } }); okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitAction"); okButton.getActionMap().put("ExitAction", new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); okButton.requestFocus(); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); //dialog.setResizable(false); dialog.setModal(true); dialog.pack(); //sets minimal sizes for components Dimension dim = mainPanel.getSize(); mainPanel.setMinimumSize(dim); mainPanel.setPreferredSize(dim); //sets size of buttons Dimension dimOkButton = okButton.getSize(); Dimension dimCancelButton = cancelButton.getSize(); int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth() : (int) dimCancelButton.getWidth(); okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setVisible(true); }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a button with an icon in it/* ww w . j av a 2 s . com*/ * * @param container - parent container * @param label - button label * @param image - button image * @param width - button width * @param height - button height * @param mnemonic - button mnemonic * @param tooltip - tool tip for button * @param placement - TableLayout placement in parent container * @param debug - turn on/off red debug borders * @return JButton with image */ public static JButton addIconButton(Container container, String label, String image, Integer width, Integer height, Integer mnemonic, String tooltip, String placement, boolean debug) { JButton button = null; if (image == null) { button = new JButton(label); } else { java.net.URL imgURL = GuiImporter.class.getResource(image); if (imgURL != null && label.length() > 0) { button = new JButton(label, new ImageIcon(imgURL)); } else if (imgURL != null) { button = new JButton(null, new ImageIcon(imgURL)); } else { button = new JButton(label); log.error("Couldn't find icon: " + image); } } if (width != null && height != null && width > 0 && height > 0) { button.setMaximumSize(new Dimension(width, height)); button.setPreferredSize(new Dimension(width, height)); button.setMinimumSize(new Dimension(width, height)); button.setSize(new Dimension(width, height)); } if (mnemonic != null) button.setMnemonic(mnemonic); button.setOpaque(!getIsMac()); button.setToolTipText(tooltip); container.add(button, placement); if (isMotif() == true) { Border b = BorderFactory.createLineBorder(Color.gray); button.setMargin(new Insets(0, 0, 0, 0)); button.setBorder(b); } if (debug == true) button.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), button.getBorder())); return button; }