Java Code Examples for javax.swing.JButton#requestFocusInWindow()

The following examples show how to use javax.swing.JButton#requestFocusInWindow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bug4213634.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public  void createAndShowGUI() {
    frame = new JFrame("TEST");
    JMenuBar mb = new JMenuBar();
    menu = mb.add(createMenu("1 - First Menu", true));
    mb.add(createMenu("2 - Second Menu", false));
    frame.setJMenuBar(mb);
    JTextArea ta = new JTextArea("This test dedicated to Nancy and Kathleen, testers and bowlers extraordinaire\n\n\nNo exception means pass.");
    frame.getContentPane().add("Center", ta);
    JButton button = new JButton("Test");
    frame.getContentPane().add("South", button);
    frame.setBounds(100, 100, 400, 400);
    frame.setVisible(true);
    button.requestFocusInWindow();
}
 
Example 2
Source File: ConfigWindow.java    From rscplus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
  JButton button = (JButton) e.getSource();
  button.setText("...");
  button.setFocusable(true);
  button.requestFocusInWindow();
}
 
Example 3
Source File: DJarInfo.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 *
 * @throws IOException Problem occurred getting JAR information
 */
private void initComponents()
    throws IOException
{
	JarFile[] jarFiles = getClassPathJars();

	// JAR Information table

	// Create the table using the appropriate table model
	JarInfoTableModel jiModel = new JarInfoTableModel();
	jiModel.load(jarFiles);

	JTable jtJarInfo = new JTable(jiModel);

	jtJarInfo.setRowMargin(0);
	jtJarInfo.getColumnModel().setColumnMargin(0);
	jtJarInfo.getTableHeader().setReorderingAllowed(false);
	jtJarInfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	jtJarInfo.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	// Add custom renderers for the table cells and headers
	for (int iCnt = 0; iCnt < jtJarInfo.getColumnCount(); iCnt++)
	{
		TableColumn column = jtJarInfo.getColumnModel().getColumn(iCnt);

		column.setPreferredWidth(150);

		column.setHeaderRenderer(new JarInfoTableHeadRend());
		column.setCellRenderer(new JarInfoTableCellRend());
	}

	// Make the table sortable
	jtJarInfo.setAutoCreateRowSorter(true);
	// ...and sort it by jar file by default
	jtJarInfo.getRowSorter().toggleSortOrder(0);

	// Put the table into a scroll pane
	JScrollPane jspJarInfoTable = new JScrollPane(jtJarInfo, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	jspJarInfoTable.getViewport().setBackground(jtJarInfo.getBackground());

	// Put the scroll pane into a panel
	JPanel jpJarInfoTable = new JPanel(new BorderLayout(10, 10));
	jpJarInfoTable.setPreferredSize(new Dimension(500, 150));
	jpJarInfoTable.add(jspJarInfoTable, BorderLayout.CENTER);
	jpJarInfoTable.setBorder(new EmptyBorder(5, 5, 5, 5));

	JButton jbOK = getOkButton(true);
	JPanel jpOK = new JPanel(new FlowLayout(FlowLayout.CENTER));
	jpOK.add(jbOK);

	getContentPane().add(jpJarInfoTable, BorderLayout.CENTER);
	getContentPane().add(jpOK, BorderLayout.SOUTH);

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	jbOK.requestFocusInWindow();
}
 
Example 4
Source File: DThrowableDetail.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DThrowableDetail.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DThrowableDetail.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DThrowableDetail.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});
	jpButtons.add(jbCopy);

	JPanel jpThrowable = new JPanel(new BorderLayout());
	jpThrowable.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on throwable's stack trace
	JTree jtrThrowable = new JTree(createThrowableNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrThrowable.setRowHeight(18);
	jtrThrowable.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrThrowable);
	// Custom tree node renderer
	jtrThrowable.setCellRenderer(new ThrowableTreeCellRend());

	// Expand all nodes in tree
	/*
	 * ...then again, not. Too much scary detail. TreeNode topNode = (TreeNode)jtrThrowable.getModel().getRoot();
	 * expandTree(jtrThrowable, new TreePath(topNode));
	 */

	JScrollPane jspThrowable = new JScrollPane(jtrThrowable, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspThrowable.setPreferredSize(new Dimension(500, 250));
	jpThrowable.add(jspThrowable, BorderLayout.CENTER);

	getContentPane().add(jpThrowable, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DThrowableDetail.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 5
Source File: DProviderInfo.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DProviderInfo.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DProviderInfo.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DProviderInfo.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});

	jpButtons.add(jbCopy);

	JPanel jpProviders = new JPanel(new BorderLayout());
	jpProviders.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on loaded security providers
	JTree jtrProviders = new JTree(createProviderNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrProviders.setRowHeight(18);
	jtrProviders.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrProviders);
	// Custom tree node renderer
	jtrProviders.setCellRenderer(new ProviderTreeCellRend());

	JScrollPane jspProviders = new JScrollPane(jtrProviders, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspProviders.setPreferredSize(new Dimension(350, 200));
	jpProviders.add(jspProviders, BorderLayout.CENTER);

	getContentPane().add(jpProviders, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DProviderInfo.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 6
Source File: DViewPEM.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 *
 * @throws CryptoException A problem was encountered getting the object's PEM encoding
 */
private void initComponents()
    throws CryptoException
{
	if (m_pem == null)
	{
		StringWriter encoded = new StringWriter();
		try (JcaPEMWriter pw = new JcaPEMWriter(encoded))
		{
			pw.writeObject(m_object);
		}
		catch (IOException e)
		{
			throw new CryptoException(RB.getString("DViewPEM.exception.message"), e);
		}
		m_pem = encoded.toString();
	}

	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);

	final JButton jbSave = new JButton(RB.getString("DViewPEM.jbSave.text"));
	jbSave.setMnemonic(RB.getString("DViewPEM.jbSave.mnemonic").charAt(0));
	if (m_chooser == null || m_pem == null)
	{
		jbSave.setEnabled(false);
	}
	else
	{
		jbSave.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent evt)
			{
				savePressed();
			}
		});
	}

	jpButtons.add(jbOK);
	jpButtons.add(jbSave);

	JPanel jpPEM = new JPanel(new BorderLayout());
	jpPEM.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load text area with the PEM encoding
	JTextArea jtaPEM = new JTextArea(m_pem);
	jtaPEM.setCaretPosition(0);
	jtaPEM.setEditable(false);
	jtaPEM.setFont(new Font(Font.MONOSPACED, Font.PLAIN, jtaPEM.getFont().getSize()));

	JScrollPane jspPEM = new JScrollPane(jtaPEM, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspPEM.setPreferredSize(new Dimension(500, 300));
	jpPEM.add(jspPEM, BorderLayout.CENTER);

	getContentPane().add(jpPEM, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 7
Source File: ToolAdapterTabbedEditorDialog.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private JButton renderInstallButton(org.esa.snap.core.gpf.descriptor.dependency.Bundle currentBundle,
                                 JPanel bundlePanel) {
    JButton installButton = new JButton() {
        @Override
        public void setText(String text) {
            super.setText(text);
            adjustDimension(this);
        }
    };
    installButton.setText((currentBundle.getLocation() == BundleLocation.REMOTE ?
            "Download and " :
            "") + "Install Now");
    installButton.setToolTipText(currentBundle.getLocation() == BundleLocation.REMOTE ?
                                         currentBundle.getDownloadURL() :
                                         currentBundle.getSource() != null ?
                                                 currentBundle.getSource().toString() : "");
    installButton.setMaximumSize(installButton.getPreferredSize());
    installButton.addActionListener((ActionEvent e) -> {
        newOperatorDescriptor.setBundles(bundleForm.applyChanges());
        org.esa.snap.core.gpf.descriptor.dependency.Bundle modifiedBundle = newOperatorDescriptor.getBundle();
        try (BundleInstaller installer = new BundleInstaller(newOperatorDescriptor)) {
            ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle("Installing bundle");
            installer.setProgressMonitor(new ProgressHandler(progressHandle, false));
            installer.setCallback(() -> {
                if (modifiedBundle.isInstalled()) {
                    Path path = newOperatorDescriptor.resolveVariables(modifiedBundle.getTargetLocation())
                            .toPath()
                            .resolve(FileUtils.getFilenameWithoutExtension(modifiedBundle.getEntryPoint()));
                    SwingUtilities.invokeLater(() -> {
                        progressHandle.finish();
                        Dialogs.showInformation(String.format("Bundle was installed in location:\n%s", path));
                        installButton.setVisible(false);
                        bundlePanel.revalidate();
                    });
                    String updateVariable = modifiedBundle.getUpdateVariable();
                    if (updateVariable != null) {
                        Optional<SystemVariable> variable = newOperatorDescriptor.getVariables()
                                .stream()
                                .filter(v -> v.getKey().equals(updateVariable))
                                .findFirst();
                        variable.ifPresent(systemVariable -> {
                            systemVariable.setShared(true);
                            systemVariable.setValue(path.toString());
                        });
                        varTable.revalidate();
                    }
                } else {
                    SwingUtilities.invokeLater(() -> {
                        progressHandle.finish();
                        Dialogs.showInformation("Bundle installation failed. \n" +
                                                        "Please see the application log for details.");
                        bundlePanel.revalidate();
                    });
                }
                return null;
            });
            installButton.setVisible(false);
            installer.install(true);
        } catch (Exception ex) {
            logger.warning(ex.getMessage());
        }
    });
    this.downloadAction = () -> {
        tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
        installButton.requestFocusInWindow();
        installButton.doClick();
        return null;
    };
    installButton.setVisible(canInstall(currentBundle));
    return installButton;
}
 
Example 8
Source File: ActionChooserScreen.java    From chipster with MIT License 4 votes vote down vote up
public ActionChooserScreen(ImportSession importSession) {
	SwingClientApplication.setPlastic3DLookAndFeel(dialog);
	dialog.setPreferredSize(new Dimension(640, 480));
	dialog.setLocationByPlatform(true);

	this.importSession = importSession;

	table = this.getTable();
	JScrollPane scroll = new JScrollPane(table);

	// upper panel
	JLabel titleLabel = new JLabel("<html><p style=" + VisualConstants.HTML_DIALOG_TITLE_STYLE + ">" + TITLE_TEXT + "</p></html>", JLabel.LEFT);
	JLabel descriptionLabel = new JLabel("<html><p>" + INFO_TEXT + "</p></html>", JLabel.LEFT);
	GridBagConstraints c = new GridBagConstraints();
	JPanel upperPanel = new JPanel(new GridBagLayout());
	c.weightx = 1.0;
	c.weighty = 1.0;
	c.fill = GridBagConstraints.HORIZONTAL;
	c.anchor = GridBagConstraints.NORTHWEST;
	c.insets.set(10, 10, 5, 10);
	c.gridx = 0;
	c.gridy = 0;
	upperPanel.add(titleLabel, c);
	c.gridy++;
	upperPanel.add(descriptionLabel, c);
	

	// lower panel
	JPanel buttonPanel = new JPanel();
	okButton = new JButton("  OK  ");
	cancelButton = new JButton("Cancel");
	copyButton = new JButton("Apply first action to all");

	okButton.addActionListener(this);
	cancelButton.addActionListener(this);
	copyButton.addActionListener(this);

	JLabel sameSettingsLabel = new JLabel("<html><p>" + "When using Import tool to import more than one files, only define the contents of the first file and then apply the same settings for the rest of the files." + "</p></html>", JLabel.LEFT);
	sameSettingsLabel.setVerticalTextPosition(JLabel.TOP);
	//sameSettingsLabel.setPreferredSize(new Dimension(550, 40));
	
	sameSettingsCheckBox = new JCheckBox("Define file structure once and apply the same settings to all files");
	sameSettingsCheckBox.setEnabled(true);
	sameSettingsCheckBox.setSelected(true);
	sameSettingsCheckBox.setPreferredSize(new Dimension(550, 40));

	buttonPanel.setLayout(new GridBagLayout());
	GridBagConstraints g = new GridBagConstraints();
	g.anchor = GridBagConstraints.NORTHWEST;
	g.gridx = 0;
	g.gridy = 0;
	g.weightx = 0.0;

	g.insets = new Insets(5, 5, 10, 5);
	buttonPanel.add(copyButton, g);
	g.gridy++;
	buttonPanel.add(sameSettingsCheckBox, g);
	g.insets = new Insets(5, 0, 10, 5);
	g.gridy++;
	g.anchor = GridBagConstraints.EAST;
	buttonPanel.add(cancelButton, g);
	g.gridx++;
	buttonPanel.add(okButton, g);

	dialog.setLayout(new BorderLayout());
	dialog.add(upperPanel, BorderLayout.NORTH);
	dialog.add(scroll, BorderLayout.CENTER);
	dialog.add(buttonPanel, BorderLayout.SOUTH);
	dialog.pack();
	dialog.pack();
	okButton.requestFocusInWindow();
	dialog.setVisible(true);
}