List of usage examples for javax.swing JButton setEnabled
public void setEnabled(boolean b)
From source file:Main.java
public Main() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w w w .j a v a2s.com*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:ListDemo.java
public ListDemo() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);//ww w .j av a 2s .c o m list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:captureplugin.drivers.DeviceCreatorDialog.java
/** * Create the GUI/*from w w w . j ava2 s . c o m*/ */ private void createGUI() { UiUtilities.registerForClosing(this); DriverIf[] drivers = DriverFactory.getInstance().getDrivers(); mDriverCombo = new JComboBox(drivers); mDriverCombo.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof DriverIf) { value = ((DriverIf) value).getDriverName(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); JPanel panel = (JPanel) getContentPane(); panel.setLayout(new GridBagLayout()); GridBagConstraints label = new GridBagConstraints(); label.insets = new Insets(5, 5, 5, 5); label.anchor = GridBagConstraints.NORTHWEST; GridBagConstraints input = new GridBagConstraints(); input.fill = GridBagConstraints.HORIZONTAL; input.weightx = 1.0; input.gridwidth = GridBagConstraints.REMAINDER; input.insets = new Insets(5, 5, 5, 5); panel.add(new JLabel(mLocalizer.msg("Name", "Name")), label); mName = new JTextField(); panel.add(mName, input); panel.add(new JLabel(mLocalizer.msg("Driver", "Driver")), label); panel.add(mDriverCombo, input); mDesc = UiUtilities.createHtmlHelpTextArea(""); mDesc.setEditable(false); panel.add(new JLabel(mLocalizer.msg("Description", "Description")), input); GridBagConstraints descC = new GridBagConstraints(); descC.weightx = 1.0; descC.weighty = 1.0; descC.fill = GridBagConstraints.BOTH; descC.gridwidth = GridBagConstraints.REMAINDER; descC.insets = new Insets(5, 5, 5, 5); panel.add(new JScrollPane(mDesc, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), descC); final Font font = new JLabel().getFont(); String desc = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc(); desc = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize() + ";\">" + desc + "</div></html>"; mDesc.setText(desc); mDesc.setFont(font); mDriverCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String description = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc(); description = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize() + ";\">" + description + "</div></html>"; mDesc.setText(description); mDesc.setFont(font); } }); final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.setEnabled(false); final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okPressed(); } }); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); mName.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateButtons(); } @Override public void insertUpdate(DocumentEvent e) { updateButtons(); } @Override public void changedUpdate(DocumentEvent e) { updateButtons(); } private void updateButtons() { ok.setEnabled(!mName.getText().trim().isEmpty()); } }); ButtonBarBuilder2 builder = new ButtonBarBuilder2(); builder.addGlue(); builder.addButton(new JButton[] { ok, cancel }); getRootPane().setDefaultButton(ok); input.insets = new Insets(5, 5, 5, 5); panel.add(builder.getPanel(), input); setSize(400, 300); }
From source file:TestOpenMailRelay.java
/** Construct a GUI and some I/O plumbing to get the output * of "TestOpenMailRelay" into the "results" textfield. *//* w w w .j av a 2 s . c o m*/ public TestOpenMailRelayGUI() throws IOException { super("Tests for Open Mail Relays"); PipedInputStream is; PipedOutputStream os; JPanel p; Container cp = getContentPane(); cp.add(BorderLayout.NORTH, p = new JPanel()); // The entry label and text field. p.add(new JLabel("Host:")); p.add(hostTextField = new JTextField(10)); hostTextField.addActionListener(runner); p.add(goButton = new JButton("Try")); goButton.addActionListener(runner); JButton cb; p.add(cb = new JButton("Clear Log")); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { results.setText(""); } }); JButton sb; p.add(sb = new JButton("Save Log")); sb.setEnabled(false); results = new JTextArea(20, 60); // Add the text area to the main part of the window (CENTER). // Wrap it in a JScrollPane to make it scroll automatically. cp.add(BorderLayout.CENTER, new JScrollPane(results)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); // end of GUI portion // Create a pair of Piped Streams. is = new PipedInputStream(); os = new PipedOutputStream(is); iis = new BufferedReader(new InputStreamReader(is, "ISO8859_1")); ps = new PrintStream(os); // Construct and start a Thread to copy data from "is" to "os". new Thread() { public void run() { try { String line; while ((line = iis.readLine()) != null) { results.append(line); results.append("\n"); } } catch (IOException ex) { JOptionPane.showMessageDialog(null, "*** Input or Output error ***\n" + ex, "Error", JOptionPane.ERROR_MESSAGE); } } }.start(); }
From source file:net.itransformers.topologyviewer.dialogs.snmpDiscovery.DiscoveryManagerDialogV2.java
private void onStopDiscoveryPost(JButton stopStartButton) { depthComboBox.setEditable(true);// ww w .j av a2 s . com addressTextField.setEditable(true); stopStartButton.setText("Start"); pauseResumeButton.setEnabled(false); stopStartButton.setEnabled(true); }
From source file:com.aw.swing.mvp.binding.BindingComponent.java
private void updateUIInternal() { JComponentDecorator.setUIReadOnly(jComponent, uiReadOnly, uiReadOnlyChangeColor); JButton linkedButton = (JButton) jComponent.getClientProperty(ATTR_LINKED_BUTTON); if (linkedButton != null) { linkedButton.setEnabled(!uiReadOnly); }//w w w . j av a 2 s . co m }
From source file:UndoExample5.java
public UndoExample5() { super("Undo/Redo Example 5"); pane = new JTextPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); // Add a menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar);// w ww .j a v a 2s .c om // Populate the menu bar createMenuBar(); // Create the undo manager and actions MonitorableUndoManager manager = new MonitorableUndoManager(); pane.getDocument().addUndoableEditListener(manager); Action undoAction = new UndoAction(manager); Action redoAction = new RedoAction(manager); // Add the actions to buttons JPanel panel = new JPanel(); final JButton undoButton = new JButton("Undo"); final JButton redoButton = new JButton("Redo"); undoButton.addActionListener(undoAction); redoButton.addActionListener(redoAction); undoButton.setEnabled(false); redoButton.setEnabled(false); panel.add(undoButton); panel.add(redoButton); getContentPane().add(panel, BorderLayout.SOUTH); // Assign the actions to keys pane.registerKeyboardAction(undoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); pane.registerKeyboardAction(redoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); // Handle events from the MonitorableUndoManager manager.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MonitorableUndoManager m = (MonitorableUndoManager) evt.getSource(); boolean canUndo = m.canUndo(); boolean canRedo = m.canRedo(); undoButton.setEnabled(canUndo); redoButton.setEnabled(canRedo); undoButton.setToolTipText(canUndo ? m.getUndoPresentationName() : null); redoButton.setToolTipText(canRedo ? m.getRedoPresentationName() : null); } }); }
From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java
public static JComponent getWebsiteDownloadButton(final String title, final String optUrlManualDownloadWebsite, final String target_dir_null_ask_user, final String optIntroText, final String[] downloadURLs, final String optIntroDialogTitle, final FileDownloadStatusInformationProvider statusProvider, final Runnable optFinishSwingTask) { final JButton res = new JMButton("Download/Update"); res.setToolTipText(/*from w w w . j a v a2 s . com*/ "<html>Click button to start automatic download<br><code><b>Check License/Disclaimers first!"); res.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final String opt_local_folder; if (target_dir_null_ask_user == null) { File file = OpenFileDialogService.getDirectoryFromUser("Select folder"); if (file == null) return; else opt_local_folder = file.getAbsolutePath(); } else { opt_local_folder = target_dir_null_ask_user; } res.setEnabled(false); res.setText("Downloading"); final BackgroundTaskStatusProviderSupportingExternalCallImpl status = new BackgroundTaskStatusProviderSupportingExternalCallImpl( "Please wait...", "Downloading files..."); BackgroundTaskHelper.issueSimpleTask(title, "Please wait...", new Runnable() { public void run() { boolean allOK = true; for (String downloadURL : downloadURLs) { allOK = performDownload(downloadURL, opt_local_folder, status); if (status.wantsToStop()) { break; } } if (status.wantsToStop()) { allOK = true; try { status.setCurrentStatusText1("Cancel..."); for (String downloadURL : downloadURLs) { String fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1); if (downloadURL.contains("|")) fileName = downloadURL.substring(downloadURL.lastIndexOf("|") + 1); String targetFileName = ReleaseInfo.getAppFolderWithFinalSep() + fileName; if (new File(targetFileName).exists()) { new File(targetFileName).delete(); status.setCurrentStatusText2("Delete " + targetFileName); } } } catch (Exception e) { // } } if (!allOK) { res.setEnabled(true); res.setText( "<html><small>Automatic download failure<br>Click here for manual download"); res.removeActionListener(res.getActionListeners()[0]); res.addActionListener(getDialogAction(optUrlManualDownloadWebsite, opt_local_folder, optIntroText, optIntroDialogTitle)); res.requestFocus(); final JDialog jd = (JDialog) ErrorMsg.findParentComponent(res, JDialog.class); if (jd != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { jd.pack(); } }); } } else { if (status.wantsToStop()) { res.setText("Canceled"); status.pleaseContinueRun(); status.setCurrentStatusText2("Canceled!"); } else { res.setText("Downloaded"); } res.setEnabled(false); if (statusProvider != null) statusProvider.finishedNewDownload(); if (optFinishSwingTask != null) SwingUtilities.invokeLater(optFinishSwingTask); } } }, null, status); } }); return res; }
From source file:net.pandoragames.far.ui.swing.FindFilePanel.java
private void initFileNamePatternPanel(SwingConfig config, ComponentRepository componentRepository) { JLabel labelPattern = new JLabel(localizer.localize("label.file-name-pattern")); labelPattern.setAlignmentX(Component.LEFT_ALIGNMENT); this.add(labelPattern); listPattern = new JComboBox(config.getFileNamePatternListModel()); listPattern.setEditable(true);/*from w ww . j av a 2 s . c om*/ listPattern .setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, config.getStandardComponentHight())); JButton buttonSavePattern = new JButton(localizer.localize("button.save-pattern")); buttonSavePattern.setEnabled(false); TwoComponentsPanel linePattern = new TwoComponentsPanel(listPattern, buttonSavePattern); linePattern.setAlignmentX(Component.LEFT_ALIGNMENT); this.add(linePattern); patternFlag = new JCheckBox(localizer.localize("label.regular-expression")); patternFlag.setAlignmentX(Component.LEFT_ALIGNMENT); patternFlag.setSelected(dataModel.getFileNamePattern().isRegex()); patternFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { dataModel.getFileNamePattern().setRegex((ItemEvent.SELECTED == event.getStateChange())); } }); patternFlag.addItemListener(componentRepository.getSearchBaseListener()); browseButtonListener.setRegexCheckBox(patternFlag); browseButtonListener.addComponentToBeDisabledForSingleFiles(patternFlag); componentRepository.getSearchBaseListener().addToBeEnabled(patternFlag); componentRepository.getResetDispatcher().addToBeEnabled(patternFlag); listPattern.addActionListener(new PatternListListener(patternFlag, componentRepository.getMessageBox())); listPattern.addActionListener(componentRepository.getSearchBaseListener()); ComboBoxEditor comboBoxEditor = new FileNamePatternEditor(buttonSavePattern); listPattern.setEditor(comboBoxEditor); browseButtonListener.setComboBox(listPattern); browseButtonListener.addComponentToBeDisabledForSingleFiles(listPattern); componentRepository.getSearchBaseListener().addToBeEnabled(listPattern); componentRepository.getResetDispatcher().addToBeEnabled(listPattern); buttonSavePattern.addActionListener( new SaveFileNamePatternListener(listPattern, patternFlag, config, componentRepository)); this.add(patternFlag); datePanel = new DateRestrictionPanel(dataModel, componentRepository, config); componentRepository.getResetDispatcher().addResetable(datePanel); datePanel.setAlignmentX(Component.LEFT_ALIGNMENT); this.add(datePanel); this.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); this.add(Box.createVerticalGlue()); }
From source file:cool.pandora.modeller.ui.jpanel.base.NewBagInPlaceFrame.java
/** * layoutSelectDataContent.//www. j a v a2s .c o m * * @param contentPanel JPanel * @param row int */ private void layoutSelectDataContent(final JPanel contentPanel, final int row) { final JLabel location = new JLabel("Select Data:"); final JButton saveAsButton = new JButton(bagView.getPropertyMessage("bag.button.browse")); saveAsButton.addActionListener(new BrowseFileHandler()); saveAsButton.setEnabled(true); saveAsButton.setToolTipText(bagView.getPropertyMessage("bag.button.browse.help")); String fileName = ""; if (bag != null) { fileName = bag.getName(); } bagNameField = new JTextField(fileName); bagNameField.setCaretPosition(fileName.length()); bagNameField.setEditable(false); bagNameField.setEnabled(false); GridBagConstraints glbc = new GridBagConstraints(); glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); contentPanel.add(location, glbc); glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); contentPanel.add(saveAsButton, glbc); glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc.ipadx = 0; contentPanel.add(bagNameField, glbc); }