Example usage for javax.swing JButton setMnemonic

List of usage examples for javax.swing JButton setMnemonic

Introduction

In this page you can find the example usage for javax.swing JButton setMnemonic.

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(int mnemonic) 

Source Link

Document

Sets the keyboard mnemonic on the current model.

Usage

From source file:org.apache.jmeter.protocol.http.gui.CookiePanel.java

private JButton createButton(String resName, char mnemonic, String command, boolean enabled) {
    JButton button = new JButton(JMeterUtils.getResString(resName));
    button.setMnemonic(mnemonic);
    button.setActionCommand(command);/*from   w  w  w  . j av a  2s .  com*/
    button.setEnabled(enabled);
    button.addActionListener(this);
    return button;
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void showExampleInfo(String helpText) {
    final JDialog dialog = new JDialog(this);
    dialog.setLocationByPlatform(true);//from   w w w  .ja va2 s  .co  m
    dialog.setPreferredSize(new Dimension(500, 250));

    JComponent helpPane = TextComponentFactory.createTextPane(helpText, true);

    JButton closeButton = new JButton("Close");
    closeButton.setMnemonic('c');
    closeButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            dialog.dispose();
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(helpPane, BorderLayout.CENTER);
    panel.add(closeButton, BorderLayout.SOUTH);

    dialog.add(panel);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:org.executequery.gui.browser.ConnectionPanel.java

private void addDriverFields(JPanel panel, GridBagConstraints gbc) {

    gbc.gridy++;/*from  w w  w .ja va  2s  .  c o  m*/
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.weightx = 0;
    panel.add(new DefaultFieldLabel("JDBC Driver:"), gbc);
    gbc.gridx = 1;
    gbc.insets.left = 5;
    gbc.insets.right = 5;
    gbc.weightx = 1.0;
    gbc.insets.top = 0;
    panel.add(driverCombo, gbc);

    driverCombo.setToolTipText("The JDBC driver to be used for this database");

    JButton button = WidgetFactory.createInlineFieldButton("New Driver");
    button.setActionCommand("addNewDriver");
    button.addActionListener(this);
    button.setMnemonic('r');

    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.insets.left = 0;
    gbc.ipadx = 10;
    gbc.insets.right = 10;
    panel.add(button, gbc);
}

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>&nbsp;&nbsp;<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  ww  .  j  ava  2s  .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   ww  w .  j  a v  a 2 s . c om

    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.executequery.gui.scriptgenerators.GenerateScriptsPanelThree.java

private JPanel createFileOutputPanel() {

    pathField = WidgetFactory.createTextField();

    final JButton browseButton = new DefaultPanelButton("Browse");
    browseButton.setMnemonic('B');
    browseButton.addActionListener(this);

    final DefaultFieldLabel label = new DefaultFieldLabel("Save Path:");

    writeToFileCheck = new JCheckBox("Write to file");
    writeToFileCheck.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean enable = writeToFileCheck.isSelected();
            browseButton.setEnabled(enable);
            pathField.setEnabled(enable);
            label.setEnabled(enable);// w  ww. ja  v a2  s.c  o m
        }
    });

    browseButton.setEnabled(false);
    pathField.setEnabled(false);
    label.setEnabled(false);

    ComponentTitledPanel panel = new ComponentTitledPanel(writeToFileCheck);
    JPanel fileOutputPanel = panel.getContentPane();
    fileOutputPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx++;
    gbc.gridy++;
    gbc.insets = new Insets(7, 5, 5, 5);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    fileOutputPanel.add(label, gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    fileOutputPanel.add(pathField, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.top = 3;
    gbc.insets.right = 5;
    fileOutputPanel.add(browseButton, gbc);

    return panel;
}

From source file:org.jab.docsearch.DocSearch.java

private JToolBar createToolBar() {

    // tool bar/*  w w w .  j a  va2 s. co m*/
    JToolBar toolBar = new JToolBar();

    // file open
    JButton buttonOpen = new JButton(new ImageIcon(getClass().getResource("/icons/fileopen.png")));
    buttonOpen.setToolTipText(I18n.getString("tooltip.open"));
    buttonOpen.setActionCommand("ac_open");
    buttonOpen.addActionListener(this);
    buttonOpen.setMnemonic(KeyEvent.VK_O);
    buttonOpen.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonOpen);

    // file save
    JButton buttonSave = new JButton(new ImageIcon(getClass().getResource("/icons/filesave.png")));
    buttonSave.setToolTipText(I18n.getString("tooltip.save"));
    buttonSave.setActionCommand("ac_save");
    buttonSave.addActionListener(this);
    buttonSave.setMnemonic(KeyEvent.VK_S);
    buttonSave.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonSave);
    toolBar.addSeparator();

    // open browser
    JButton buttonBrowser = new JButton(new ImageIcon(getClass().getResource("/icons/html.png")));
    buttonBrowser.setToolTipText(I18n.getString("tooltip.open_in_browser"));
    buttonBrowser.setActionCommand("ac_openinbrowser");
    buttonBrowser.addActionListener(this);
    buttonBrowser.setMnemonic(KeyEvent.VK_E);
    buttonBrowser.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonBrowser);
    toolBar.addSeparator();

    // home
    JButton buttonHome = new JButton(new ImageIcon(getClass().getResource("/icons/home.png")));
    buttonHome.setToolTipText(I18n.getString("tooltip.home"));
    buttonHome.setActionCommand("ac_home");
    buttonHome.addActionListener(this);
    buttonHome.setMnemonic(KeyEvent.VK_H);
    toolBar.add(buttonHome);

    // refresh
    JButton buttonRefresh = new JButton(new ImageIcon(getClass().getResource("/icons/refresh.png")));
    buttonRefresh.setToolTipText(I18n.getString("tooltip.refresh"));
    buttonRefresh.setActionCommand("ac_refresh");
    buttonRefresh.addActionListener(this);
    buttonRefresh.setMnemonic(KeyEvent.VK_L);
    toolBar.add(buttonRefresh);
    toolBar.addSeparator();

    // result
    JButton buttonResult = new JButton(new ImageIcon(getClass().getResource("/icons/search_results.png")));
    buttonResult.setToolTipText(I18n.getString("tooltip.results"));
    buttonResult.setActionCommand("ac_result");
    buttonResult.addActionListener(this);
    buttonResult.setMnemonic(KeyEvent.VK_R);
    toolBar.add(buttonResult);
    toolBar.addSeparator();

    // bookmark
    JButton buttonBookMark = new JButton(new ImageIcon(getClass().getResource("/icons/bookmark.png")));
    buttonBookMark.setToolTipText(I18n.getString("tooltip.add_bookmark"));
    buttonBookMark.setActionCommand("ac_addbookmark");
    buttonBookMark.addActionListener(this);
    buttonBookMark.setMnemonic(KeyEvent.VK_M);
    toolBar.add(buttonBookMark);
    toolBar.addSeparator();

    // print
    JButton buttonPrint = new JButton(new ImageIcon(getClass().getResource("/icons/fileprint.png")));
    buttonPrint.setToolTipText(I18n.getString("tooltip.print"));
    buttonPrint.setActionCommand("ac_print");
    buttonPrint.addActionListener(this);
    buttonPrint.setMnemonic(KeyEvent.VK_P);
    toolBar.add(buttonPrint);
    toolBar.addSeparator();

    // setting
    JButton buttonSetting = new JButton(new ImageIcon(getClass().getResource("/icons/configure.png")));
    buttonSetting.setToolTipText(I18n.getString("tooltip.settings"));
    buttonSetting.setActionCommand("ac_settings");
    buttonSetting.addActionListener(this);
    buttonSetting.setMnemonic(KeyEvent.VK_HOME);
    toolBar.add(buttonSetting);
    toolBar.addSeparator();

    // stop
    buttonStop = new JButton(new ImageIcon(getClass().getResource("/icons/stop.png")));
    buttonStop.setToolTipText(I18n.getString("tooltip.stop"));
    buttonStop.setActionCommand("ac_stop");
    buttonStop.addActionListener(this);
    buttonStop.setMnemonic(KeyEvent.VK_X);
    toolBar.add(buttonStop);
    toolBar.addSeparator();

    //
    toolBar.setFloatable(false);

    // finished
    return toolBar;
}

From source file:org.languagetool.gui.ConfigurationDialog.java

public boolean show(List<Rule> rules) {
    configChanged = false;//from  w  w  w .  j  a  va2  s .  com
    if (original != null) {
        config.restoreState(original);
    }
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiConfigWindowTitle"));
    // close dialog when user presses Escape key:
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener actionListener = new ActionListener() {
        @Override
        public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    };
    JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    configurableRules.clear();

    Language lang = config.getLanguage();
    if (lang == null) {
        lang = Languages.getLanguageForLocale(Locale.getDefault());
    }

    String specialTabNames[] = config.getSpecialTabNames();
    int numConfigTrees = 2 + specialTabNames.length;
    configTree = new JTree[numConfigTrees];
    JPanel checkBoxPanel[] = new JPanel[numConfigTrees];
    DefaultMutableTreeNode rootNode;
    GridBagConstraints cons;

    for (int i = 0; i < numConfigTrees; i++) {
        checkBoxPanel[i] = new JPanel();
        cons = new GridBagConstraints();
        checkBoxPanel[i].setLayout(new GridBagLayout());
        cons.anchor = GridBagConstraints.NORTHWEST;
        cons.gridx = 0;
        cons.weightx = 1.0;
        cons.weighty = 1.0;
        cons.fill = GridBagConstraints.HORIZONTAL;
        Collections.sort(rules, new CategoryComparator());
        if (i == 0) {
            rootNode = createTree(rules, false, null); //  grammar options
        } else if (i == 1) {
            rootNode = createTree(rules, true, null); //  Style options
        } else {
            rootNode = createTree(rules, true, specialTabNames[i - 2]); //  Special tab options
        }
        configTree[i] = new JTree(getTreeModel(rootNode));

        configTree[i].applyComponentOrientation(ComponentOrientation.getOrientation(lang.getLocale()));

        configTree[i].setRootVisible(false);
        configTree[i].setEditable(false);
        configTree[i].setCellRenderer(new CheckBoxTreeCellRenderer());
        TreeListener.install(configTree[i]);
        checkBoxPanel[i].add(configTree[i], cons);
        configTree[i].addMouseListener(getMouseAdapter());
    }

    JPanel portPanel = new JPanel();
    portPanel.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.anchor = GridBagConstraints.WEST;
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.0f;
    if (!insideOffice) {
        createNonOfficeElements(cons, portPanel);
    } else {
        createOfficeElements(cons, portPanel);
    }

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
    okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
    okButton.setActionCommand(ACTION_COMMAND_OK);
    okButton.addActionListener(this);
    JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
    cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
    cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
    cancelButton.addActionListener(this);
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    buttonPanel.add(okButton, cons);
    buttonPanel.add(cancelButton, cons);

    JTabbedPane tabpane = new JTabbedPane();

    JPanel jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);

    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.NORTHWEST;
    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getMotherTonguePanel(cons), cons);

    if (insideOffice) {
        cons.gridy += 3;
    } else {
        cons.gridy++;
    }
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getNgramPanel(cons), cons);

    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getWord2VecPanel(cons), cons);

    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(portPanel, cons);
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.WEST;
    for (JPanel extra : extraPanels) {
        //in case it wasn't in a containment hierarchy when user changed L&F
        SwingUtilities.updateComponentTreeUI(extra);
        cons.gridy++;
        jPane.add(extra, cons);
    }

    cons.gridy++;
    cons.fill = GridBagConstraints.BOTH;
    cons.weighty = 1.0f;
    jPane.add(new JPanel(), cons);

    tabpane.addTab(messages.getString("guiGeneral"), jPane);

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[0]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(0), cons);

    tabpane.addTab(messages.getString("guiGrammarRules"), jPane);

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[1]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(1), cons);

    cons.gridx = 0;
    cons.gridy++;
    cons.weightx = 5.0f;
    cons.weighty = 5.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(new JScrollPane(getSpecialRuleValuePanel()), cons);

    tabpane.addTab(messages.getString("guiStyleRules"), jPane);

    for (int i = 0; i < specialTabNames.length; i++) {
        jPane = new JPanel();
        jPane.setLayout(new GridBagLayout());
        cons = new GridBagConstraints();
        cons.insets = new Insets(4, 4, 4, 4);
        cons.gridx = 0;
        cons.gridy = 0;
        cons.weightx = 10.0f;
        cons.weighty = 10.0f;
        cons.fill = GridBagConstraints.BOTH;
        jPane.add(new JScrollPane(checkBoxPanel[i + 2]), cons);
        cons.weightx = 0.0f;
        cons.weighty = 0.0f;

        cons.gridx = 0;
        cons.gridy++;
        cons.fill = GridBagConstraints.NONE;
        cons.anchor = GridBagConstraints.LINE_END;
        jPane.add(getTreeButtonPanel(i + 2), cons);

        tabpane.addTab(specialTabNames[i], jPane);
    }

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    if (insideOffice) {
        JLabel versionText = new JLabel(messages.getString("guiUColorHint"));
        versionText.setForeground(Color.blue);
        jPane.add(versionText, cons);
        cons.gridy++;
    }

    cons.weightx = 2.0f;
    cons.weighty = 2.0f;
    cons.fill = GridBagConstraints.BOTH;

    jPane.add(new JScrollPane(getUnderlineColorPanel(rules)), cons);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.NORTHWEST;
    contentPane.add(tabpane, cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.EAST;
    contentPane.add(buttonPanel, cons);

    dialog.pack();
    // center on screen:
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
            screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
    //  add Color tab after dimension was set
    tabpane.addTab(messages.getString("guiUnderlineColor"), jPane);

    for (JPanel extra : this.extraPanels) {
        if (extra instanceof SavablePanel) {
            ((SavablePanel) extra).componentShowing();
        }
    }
    dialog.setVisible(true);
    return configChanged;
}

From source file:org.openmicroscopy.shoola.util.ui.MessengerDialog.java

/**
 * Formats the specified button.//from  w w  w .  j a  v a 2  s .  c o m
 * 
 * @param b         The button to format.
 * @param mnemonic   The key-code that indicates a mnemonic key.
 * @param tooltip   The button's tooltip.
 * @param actionID   The action id associated to the passed button.
 */
private void formatButton(JButton b, int mnemonic, String tooltip, int actionID) {
    b.setMnemonic(mnemonic);
    b.setOpaque(false);
    b.setToolTipText(tooltip);
    b.addActionListener(this);
    b.setActionCommand("" + actionID);
}

From source file:pcgen.gui2.dialog.ChooserDialog.java

private void initComponents() {
    setTitle(chooser.getName());//from  w ww .j a  v  a 2s.  com
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //detach listeners from the chooser
            treeViewModel.setDelegate(null);
            listModel.setListFacade(null);
            chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
        }

    });
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    JSplitPane split = new JSplitPane();
    JPanel leftPane = new JPanel(new BorderLayout());
    if (availTable != null) {
        availTable.setAutoCreateRowSorter(true);
        availTable.setTreeViewModel(treeViewModel);
        availTable.getRowSorter().toggleSortOrder(0);
        availTable.addActionListener(this);
        leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
    } else {
        availInput.addActionListener(this);
        Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
        availInput.setMaximumSize(maxDim);
        JPanel availPanel = new JPanel();
        availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
        availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
        availPanel.add(Box.createVerticalGlue());
        availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
        availPanel.add(availInput);
        availPanel.add(Box.createVerticalGlue());
        leftPane.add(availPanel, BorderLayout.WEST);
    }

    JPanel buttonPane1 = new JPanel(new FlowLayout());
    JButton addButton = new JButton(chooser.getAddButtonName());
    addButton.setActionCommand("ADD");
    addButton.addActionListener(this);
    buttonPane1.add(addButton);
    buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
    leftPane.add(buttonPane1, BorderLayout.SOUTH);

    split.setLeftComponent(leftPane);

    JPanel rightPane = new JPanel(new BorderLayout());
    JPanel labelPane = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
    remainingLabel.setText(chooser.getRemainingSelections().get().toString());
    labelPane.add(remainingLabel, gbc);
    labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
    rightPane.add(labelPane, BorderLayout.NORTH);

    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addActionListener(this);
    rightPane.add(new JScrollPane(list), BorderLayout.CENTER);

    JPanel buttonPane2 = new JPanel(new FlowLayout());
    buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
    JButton removeButton = new JButton(chooser.getRemoveButtonName());
    removeButton.setActionCommand("REMOVE");
    removeButton.addActionListener(this);
    buttonPane2.add(removeButton);
    rightPane.add(buttonPane2, BorderLayout.SOUTH);

    split.setRightComponent(rightPane);

    if (chooser.isInfoAvailable()) {
        JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        infoSplit.setTopComponent(split);
        infoSplit.setBottomComponent(infoPane);
        infoSplit.setResizeWeight(0.8);
        pane.add(infoSplit, BorderLayout.CENTER);
        if (availTable != null) {
            availTable.getSelectionModel().addListSelectionListener(this);
        }
    } else {
        pane.add(split, BorderLayout.CENTER);
    }
    JPanel bottomPane = new JPanel(new FlowLayout());
    JButton button = new JButton(LanguageBundle.getString("in_ok")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok")); //$NON-NLS-1$
    button.setActionCommand("OK");
    button.addActionListener(this);
    bottomPane.add(button);
    button = new JButton(LanguageBundle.getString("in_cancel")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel")); //$NON-NLS-1$
    button.setActionCommand("CANCEL");
    button.addActionListener(this);
    bottomPane.add(button);
    pane.add(bottomPane, BorderLayout.SOUTH);
}