List of usage examples for javax.swing JButton setActionCommand
public void setActionCommand(String actionCommand)
From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java
private void init() throws IOException { hostField = new DisabledField(); userNameField = WidgetFactory.createTextField(); passwordField = WidgetFactory.createPasswordField(); portField = WidgetFactory.createNumberTextField(); mainPanel = new TextFieldPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(10, 10, 10, 10); gbc.gridy = 0;//from w w w. ja v a2s . c o m gbc.gridx = 0; gbc.insets.bottom = 5; gbc.gridwidth = GridBagConstraints.REMAINDER; mainPanel.add(new DefaultFieldLabel( FileUtils.loadResource("org/executequery/gui/browser/resource/ssh-tunnel.html")), gbc); addLabelFieldPair(mainPanel, "SSH Host:", hostField, "The SSH host server for the tunnel", gbc); addLabelFieldPair(mainPanel, "SSH Port:", portField, "The SSH server port", gbc); addLabelFieldPair(mainPanel, "SSH User Name:", userNameField, "The SSH user name for the tunnel", gbc); addLabelFieldPair(mainPanel, "SSH Password:", passwordField, "The SSH user password for the tunnel", gbc); savePwdCheck = ActionUtilities.createCheckBox("Store Password", "setStorePassword"); JButton showPassword = new LinkButton("Show Password"); showPassword.setActionCommand("showPassword"); showPassword.addActionListener(this); JPanel passwordOptionsPanel = new JPanel(new GridBagLayout()); addComponents(passwordOptionsPanel, new ComponentToolTipPair[] { new ComponentToolTipPair(savePwdCheck, "Store the password with the connection information"), new ComponentToolTipPair(showPassword, "Show the password in plain text") }); gbc.gridy++; gbc.gridx = 1; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; mainPanel.add(passwordOptionsPanel, gbc); JScrollPane scrollPane = new JScrollPane(mainPanel); scrollPane.setBorder(null); useSshCheckbox = ActionUtilities.createCheckBox(this, "Connect Using an SSH Tunnel", "useSshSelected"); ComponentTitledPanel titledPanel = new ComponentTitledPanel(useSshCheckbox); JPanel panel = titledPanel.getContentPane(); panel.setLayout(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(titledPanel, BorderLayout.NORTH); }
From source file:org.executequery.gui.drivers.AbstractDriverPanel.java
private void init() { ReflectiveAction action = new ReflectiveAction(this); JButton browseButton = new DefaultButton(action, getString("AbstractDriverPanel.addLibraryButton"), "browseDrivers"); JButton removeButton = new DefaultButton(action, getString("AbstractDriverPanel.addRemoveButton"), "removeDrivers"); JButton findButton = new DefaultInlineFieldButton(action); findButton.setText(getString("AbstractDriverPanel.addFindButton")); findButton.setActionCommand("findDriverClass"); jarPathListModel = new DefaultListModel(); nameField = textFieldWithKey("AbstractDriverPanel.driverNameToolTip"); descField = textFieldWithKey("AbstractDriverPanel.descriptionToolTip"); // classField = textFieldWithKey("AbstractDriverPanel.classNameToolTip"); classComboModel = new DynamicComboBoxModel(); classField = WidgetFactory.createComboBox(classComboModel); classField.setToolTipText(getString("AbstractDriverPanel.classNameToolTip")); classField.setEditable(true);/*from w w w . j av a2s.c om*/ jarPathList = new JList(jarPathListModel); jarPathList.setToolTipText(getString("AbstractDriverPanel.pathToolTip")); JScrollPane jarPathListScrollPane = new JScrollPane(jarPathList) { private int height = 120; @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.height = height; return size; } @Override public Dimension getMinimumSize() { Dimension size = super.getMinimumSize(); size.height = height; return size; } }; nameField.addFocusListener(new DriverNameFieldListener(this)); databaseNameCombo = WidgetFactory.createComboBox(createDatabaseComboValues()); databaseNameCombo.setToolTipText(getString("AbstractDriverPanel.databaseToolTip")); databaseNameCombo.addItemListener(this); urlComboModel = new DynamicComboBoxModel(); driverUrlCombo = WidgetFactory.createComboBox(urlComboModel); driverUrlCombo.setToolTipText(getString("AbstractDriverPanel.jdbcUrlToolTip")); driverUrlCombo.setEditable(true); JPanel base = new TextFieldPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy++; gbc.insets = new Insets(10, 10, 5, 0); gbc.anchor = GridBagConstraints.NORTHWEST; base.add(labelWithKey("AbstractDriverPanel.driverNameLabel"), gbc); gbc.gridy++; gbc.insets.top = 0; base.add(labelWithKey("AbstractDriverPanel.descriptionLabel"), gbc); gbc.gridy++; base.add(labelWithKey("AbstractDriverPanel.databaseLabel"), gbc); gbc.gridy++; base.add(labelWithKey("AbstractDriverPanel.jdbcUrlLabel"), gbc); gbc.gridy++; base.add(labelWithKey("AbstractDriverPanel.pathLabel"), gbc); gbc.gridy += 4; base.add(labelWithKey("AbstractDriverPanel.classNameLabel"), gbc); gbc.gridy = 0; gbc.gridx = 1; gbc.insets.right = 10; gbc.insets.top = 10; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.REMAINDER; base.add(nameField, gbc); gbc.gridy++; gbc.insets.top = 0; base.add(descField, gbc); gbc.gridy++; base.add(databaseNameCombo, gbc); gbc.gridy++; base.add(driverUrlCombo, gbc); gbc.gridy++; gbc.gridwidth = 1; gbc.insets.right = 0; gbc.gridheight = 2; gbc.insets.top = 5; base.add(jarPathListScrollPane, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.insets.right = 10; gbc.gridheight = 1; gbc.insets.left = 5; gbc.fill = GridBagConstraints.HORIZONTAL; base.add(browseButton, gbc); gbc.gridy++; gbc.insets.top = 0; base.add(removeButton, gbc); gbc.gridy += 3; gbc.gridx = 1; gbc.weightx = 1.0; gbc.insets.right = 0; gbc.insets.left = 10; gbc.insets.top = 0; base.add(classField, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.weighty = 1.0; gbc.insets.right = 10; gbc.insets.left = 5; gbc.fill = GridBagConstraints.HORIZONTAL; base.add(findButton, gbc); add(base, BorderLayout.CENTER); }
From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java
private void init() { Border emptyBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2); JPanel textPanel = new JPanel(new BorderLayout()); textPanel.setBorder(emptyBorder);//w w w . j a v a 2 s. c om textArea = createTextArea(); textArea.setLineWrap(false); textArea.setMargin(new Insets(2, 2, 2, 2)); textPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); JPanel imagePanel = null; imagePanel = new JPanel(new BorderLayout()); imagePanel.setBorder(emptyBorder); if (isImage()) { ImageIcon image = loadImageData(); if (image != null) { JLabel imageLabel = new JLabel(image); imagePanel.add(new JScrollPane(imageLabel), BorderLayout.CENTER); } setTextAreaText(textArea, CANNOT_DISPLAY_BINARY_DATA_AS_TEXT); } else { imagePanel.add(new JLabel("Unsupported format", JLabel.CENTER)); loadTextData(); } JPanel binaryPanel = new JPanel(new BorderLayout()); binaryPanel.setBorder(emptyBorder); binaryStringTextArea = createTextArea(); binaryPanel.add(new JScrollPane(binaryStringTextArea), BorderLayout.CENTER); tabbedPane = new JTabbedPane(); tabbedPane.addChangeListener(this); tabbedPane.addTab("Text", textPanel); tabbedPane.addTab("Image", imagePanel); tabbedPane.addTab("Binary", binaryPanel); JPanel contentPanel = new JPanel(new BorderLayout()); contentPanel.setPreferredSize(new Dimension(400, 300)); contentPanel.add(tabbedPane, BorderLayout.CENTER); JLabel descriptionLabel = new JLabel(formatDescriptionString()); descriptionLabel.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 0)); contentPanel.add(descriptionLabel, BorderLayout.SOUTH); JButton closeButton = new JButton("Close"); closeButton.setActionCommand("close"); JButton saveButton = new JButton("Save As"); saveButton.setActionCommand("save"); saveButton.addActionListener(this); closeButton.addActionListener(this); addActionButton(saveButton); addActionButton(closeButton); setPreferredSize(new Dimension(500, 420)); addContentPanel(contentPanel); textArea.requestFocus(); }
From source file:org.executequery.gui.editor.ManageShortcutsPanel.java
private JButton createCancelButton() { JButton button = new DefaultPanelButton(bundleString("cancelButton")); button.setActionCommand(CANCEL_COMMAND_NAME); button.addActionListener(this); return button; }
From source file:org.executequery.gui.editor.ManageShortcutsPanel.java
private JButton createSaveButton() { JButton button = new DefaultPanelButton(bundleString("okButton")); button.setActionCommand(SAVE_COMMAND_NAME); button.addActionListener(this); return button; }
From source file:org.executequery.gui.ExecuteSqlScriptPanel.java
private void init() throws Exception { fileNameField = WidgetFactory.createTextField(); connectionsCombo = WidgetFactory.createComboBox(); combosGroup = new TableSelectionCombosGroup(connectionsCombo); actionOnErrorCombo = WidgetFactory.createComboBox(); ActionOnError[] actionsOnError = { ActionOnError.HALT, ActionOnError.CONTINUE }; actionOnErrorCombo.setModel(new DefaultComboBoxModel(actionsOnError)); outputPanel = new LoggingOutputPanel(); statusBar = new SqlTextPaneStatusBar(); statusBar.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 1)); JButton button = WidgetFactory.createInlineFieldButton("Browse"); button.setActionCommand("browse"); button.addActionListener(this); button.setMnemonic('r'); logOutputCheckBox = new JCheckBox( "<html> <i>Note:</i> This will slow down the process significantly </html>"); JPanel mainPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 0;//from w w w.j av a2 s. c om gbc.gridx = 0; gbc.gridheight = 1; gbc.insets.top = 7; gbc.insets.bottom = 5; gbc.insets.right = 5; gbc.insets.left = 5; gbc.anchor = GridBagConstraints.NORTHWEST; mainPanel.add(new JLabel("Connection:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.insets.top = 5; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(connectionsCombo, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 5; mainPanel.add(new JLabel("Action on Error:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets.top = 0; mainPanel.add(actionOnErrorCombo, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 5; mainPanel.add(new JLabel("Input File:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.insets.top = 0; mainPanel.add(fileNameField, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.insets.left = 0; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(button, gbc); gbc.gridy++; gbc.gridx = 0; gbc.insets.top = 5; gbc.insets.left = 5; mainPanel.add(new JLabel("Log output:"), gbc); gbc.gridx = 1; gbc.insets.top = 2; gbc.insets.left = 0; mainPanel.add(logOutputCheckBox, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weighty = 1.0; gbc.weightx = 1.0; gbc.insets.top = 5; gbc.insets.left = 5; gbc.insets.bottom = 0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.BOTH; mainPanel.add(outputPanel, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weighty = 0; gbc.insets.bottom = 5; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(statusBar, gbc); mainPanel.setBorder(BorderFactory.createEtchedBorder()); int minimumButtonWidth = 85; startButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Start", "start"); rollbackButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Commit", "commit"); commitButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Rollback", "rollback"); stopButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Stop", "stop"); rollbackButton.setEnabled(false); commitButton.setEnabled(false); stopButton.setEnabled(false); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 5)); buttonPanel.add(startButton); buttonPanel.add(rollbackButton); buttonPanel.add(commitButton); buttonPanel.add(stopButton); add(mainPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); EventMediator.registerListener(this); }
From source file:org.executequery.gui.ExportResultSetPanel.java
private void init() throws Exception { fileNameField = WidgetFactory.createTextField(); connectionsCombo = WidgetFactory.createComboBox(); String[] delims = { "|", ",", ";", "#" }; delimiterCombo = WidgetFactory.createComboBox(delims); delimiterCombo.setEditable(true);//from w ww. java 2s . com combosGroup = new TableSelectionCombosGroup(connectionsCombo); includeColumNamesCheck = new JCheckBox("Include column names as first row"); sqlText = new SimpleSqlTextPanel(); // sqlText.getTextPane().setBackground(Color.WHITE); sqlText.setBorder(null); sqlText.setScrollPaneBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, UIUtils.getDefaultBorderColour())); statusBar = new SqlTextPaneStatusBar(); JPanel sqlPanel = new JPanel(new BorderLayout()); sqlPanel.add(sqlText, BorderLayout.CENTER); sqlPanel.add(statusBar, BorderLayout.SOUTH); statusBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 1)); outputPanel = new LoggingOutputPanel(); FlatSplitPane splitPane = new FlatSplitPane(JSplitPane.VERTICAL_SPLIT, sqlPanel, outputPanel); splitPane.setResizeWeight(0.5); splitPane.setDividerLocation(0.8); splitPane.setDividerSize(5); JButton button = WidgetFactory.createInlineFieldButton("Browse"); button.setActionCommand("browse"); button.addActionListener(this); button.setMnemonic('r'); JPanel mainPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 0; gbc.gridx = 0; gbc.gridheight = 1; gbc.insets.top = 5; gbc.insets.bottom = 5; gbc.insets.right = 5; gbc.insets.left = 5; gbc.anchor = GridBagConstraints.NORTHWEST; mainPanel.add(new JLabel("Connection:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(connectionsCombo, gbc); gbc.insets.left = 5; gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 0; mainPanel.add(new JLabel("Data Delimiter:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(delimiterCombo, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 2; mainPanel.add(new JLabel("Output File:"), gbc); gbc.gridx = 1; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(fileNameField, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.insets.left = 0; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(button, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.top = 2; gbc.insets.left = 5; mainPanel.add(includeColumNamesCheck, gbc); gbc.gridy++; gbc.insets.bottom = 10; mainPanel.add(new JLabel(instructionNote()), gbc); gbc.gridy++; gbc.gridx = 0; gbc.weighty = 1.0; gbc.weightx = 1.0; gbc.insets.top = 0; gbc.insets.left = 5; gbc.insets.bottom = 5; gbc.fill = GridBagConstraints.BOTH; mainPanel.add(splitPane, gbc); mainPanel.setBorder(BorderFactory.createEtchedBorder()); int minimumButtonWidth = 85; executeButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Execute", "executeAndExport"); stopButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Stop", "stop"); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 5)); buttonPanel.add(executeButton); buttonPanel.add(stopButton); stopButton.setEnabled(false); add(mainPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); // register as a keyword and connection listener EventMediator.registerListener(this); JTextPane textPane = sqlText.getTextPane(); ActionMap actionMap = textPane.getActionMap(); String actionKey = "executeQueryAction"; actionMap.put(actionKey, executeQueryAction); InputMap inputMap = textPane.getInputMap(); inputMap.put(EXECUTE_KEYSTROKE, actionKey); JPopupMenu popupMenu = sqlText.getPopup(); popupMenu.addSeparator(); popupMenu.add(executeQueryAction); }
From source file:org.fao.gast.gui.GuiBuilder.java
private JButton buildButton(Element button, FormPanel form) { String image = button.getChildText("image"); String label = button.getChildText("label"); String action = button.getChildText("action"); JButton btn = new JButton(label, retrieveImage(image)); btn.setActionCommand(action); btn.addActionListener(form);//from w ww . j a va 2 s . com return btn; }
From source file:org.fhaes.gui.ShapeFileDialog.java
@SuppressWarnings("unchecked") private void initGUI() { setBounds(100, 100, 582, 333);//w w w.j av a 2 s . c om getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new MigLayout("", "[right][grow]", "[][][][grow]")); { JLabel lblOutputFilename = new JLabel("Output filename:"); contentPanel.add(lblOutputFilename, "cell 0 0,alignx trailing"); } { txtFilename = new JTextField(); txtFilename.getDocument().addDocumentListener(this); contentPanel.add(txtFilename, "flowx,cell 1 0,growx"); txtFilename.setColumns(10); } { JButton btnBrowse = new JButton("Browse"); btnBrowse.setActionCommand("Browse"); btnBrowse.addActionListener(this); contentPanel.add(btnBrowse, "cell 1 0"); } { JLabel lblAttributeTableStyle = new JLabel("Attribute table style:"); contentPanel.add(lblAttributeTableStyle, "cell 0 1,alignx trailing"); } { radStyle1 = new JRadioButton("One marker per site with multiple year attributes"); radStyle1.setActionCommand("Style1"); radStyle1.addActionListener(this); // radStyle1.setSelected(true); buttonGroup.add(radStyle1); contentPanel.add(radStyle1, "cell 1 1"); } { radStyle2 = new JRadioButton("Multiple markers per site, one for each year"); radStyle2.setActionCommand("Style2"); radStyle2.addActionListener(this); buttonGroup.add(radStyle2); new RadioButtonWrapper(buttonGroup, PrefKey.SHAPEFILE_OUTPUT_STYLE, "Style1"); contentPanel.add(radStyle2, "cell 1 2"); } { JPanel panel = new JPanel(); contentPanel.add(panel, "cell 0 3,alignx right,growy"); panel.setLayout(new MigLayout("insets n n n 0", "[119px]", "[15px]")); { JLabel lblYearsToInclude = new JLabel("Years to include:"); panel.add(lblYearsToInclude, "cell 0 0,alignx left,aligny top"); } } { JPanel panel = new JPanel(); contentPanel.add(panel, "cell 1 3,alignx left,growy"); panel.setLayout(new MigLayout("", "[160px:160px][][160px:160px]", "[][grow]")); { JLabel lblAvailableYears = new JLabel("Available:"); panel.add(lblAvailableYears, "cell 0 0,alignx center"); } { lblSelectedYears = new JLabel("Selected:"); panel.add(lblSelectedYears, "cell 2 0,alignx center"); } { JScrollPane scrollPane = new JScrollPane(); panel.add(scrollPane, "cell 0 1,grow"); { lstAvailableYears = new JList(); lstAvailableYears.setModel(availableYearsModel); scrollPane.setViewportView(lstAvailableYears); } } { JButton btnRemove = new JButton("<"); btnRemove.setActionCommand("removeYear"); btnRemove.addActionListener(this); { JButton btnAdd = new JButton(">"); btnAdd.setActionCommand("addYear"); btnAdd.addActionListener(this); panel.add(btnAdd, "flowy,cell 1 1"); } panel.add(btnRemove, "cell 1 1"); } { JScrollPane scrollPane = new JScrollPane(); panel.add(scrollPane, "cell 2 1,grow"); { lstSelectedYears = new JList(); lstSelectedYears.setModel(selectedYearsModel); selectedYearsModel.addListDataListener(new ListDataListener() { @Override public void contentsChanged(ListDataEvent arg0) { pingLayout(); } @Override public void intervalAdded(ListDataEvent arg0) { pingLayout(); } @Override public void intervalRemoved(ListDataEvent arg0) { pingLayout(); } }); scrollPane.setViewportView(lstSelectedYears); } } } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { btnOK = new JButton("OK"); btnOK.setActionCommand("OK"); btnOK.addActionListener(this); buttonPane.add(btnOK); getRootPane().setDefaultButton(btnOK); btnOK.setEnabled(false); } { JButton btnCancel = new JButton("Cancel"); btnCancel.setActionCommand("Cancel"); btnCancel.addActionListener(this); buttonPane.add(btnCancel); } } this.setLocationRelativeTo(parent); this.setIconImage(Builder.getApplicationIcon()); this.setTitle("Generate shapefile"); pingLayout(); }
From source file:org.graphwalker.GUI.App.java
private JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText, boolean enabled) { // Look for the image. String imgLocation = "resources/icons/" + imageName + ".png"; URL imageURL = App.class.getResource(imgLocation); // Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText);/* ww w . j a va 2 s . com*/ button.addActionListener(this); button.setEnabled(enabled); if (imageURL != null) { // image found button.setIcon(new ImageIcon(imageURL, altText)); } else { // no image found button.setText(altText); logger.error("Resource not found: " + imgLocation); } return button; }