Example usage for javax.swing JToggleButton addActionListener

List of usage examples for javax.swing JToggleButton addActionListener

Introduction

In this page you can find the example usage for javax.swing JToggleButton addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:org.ut.biolab.medsavant.client.view.LoginView.java

/** This method is called from within the constructor to
 * initialize the form.//from w w  w  .  jav  a  2 s . c  om
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    titlePanel = new javax.swing.JPanel();
    userField = new javax.swing.JTextField();
    passwordField = new javax.swing.JPasswordField();
    spiralPanel = new javax.swing.JPanel();
    versionLabel = new javax.swing.JLabel();
    javax.swing.JLabel userLabel = new javax.swing.JLabel();
    javax.swing.JLabel passwordLabel = new javax.swing.JLabel();
    javax.swing.JToggleButton button_settings = new javax.swing.JToggleButton();
    detailsPanel = new javax.swing.JPanel();
    javax.swing.JLabel hostLabel = new javax.swing.JLabel();
    hostField = new javax.swing.JTextField();
    javax.swing.JLabel portLabel = new javax.swing.JLabel();
    portField = new javax.swing.JTextField();
    javax.swing.JButton dbCreateButton = new javax.swing.JButton();
    databaseField = new javax.swing.JTextField();
    javax.swing.JLabel databaseLabel = new javax.swing.JLabel();
    javax.swing.JButton dbRemoveButton = new javax.swing.JButton();
    loginButton = new javax.swing.JButton();
    progressSigningIn = new javax.swing.JProgressBar();

    setLayout(new java.awt.GridBagLayout());

    titlePanel.setBackground(new java.awt.Color(255, 255, 255));
    titlePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6));
    titlePanel.setMaximumSize(new java.awt.Dimension(400, 32767));
    titlePanel.setMinimumSize(new java.awt.Dimension(400, 800));
    titlePanel.setOpaque(false);

    userField.setColumns(25);
    userField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    userField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            userFieldKeyPressed(evt);
        }
    });

    passwordField.setColumns(25);
    passwordField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    passwordField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            passwordFieldKeyPressed(evt);
        }
    });

    spiralPanel.setPreferredSize(new java.awt.Dimension(150, 150));

    javax.swing.GroupLayout spiralPanelLayout = new javax.swing.GroupLayout(spiralPanel);
    spiralPanel.setLayout(spiralPanelLayout);
    spiralPanelLayout.setHorizontalGroup(spiralPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
    spiralPanelLayout.setVerticalGroup(spiralPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 150, Short.MAX_VALUE));

    versionLabel.setFont(versionLabel.getFont());
    versionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    versionLabel.setText("version information");

    userLabel.setFont(new java.awt.Font("Helvetica", 0, 12)); // NOI18N
    userLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    userLabel.setText("USERNAME");

    passwordLabel.setFont(new java.awt.Font("Helvetica", 0, 12)); // NOI18N
    passwordLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    passwordLabel.setText("PASSWORD");

    button_settings.setText("Connection Settings");
    button_settings.putClientProperty("JButton.buttonType", "textured");
    button_settings.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            button_settingsActionPerformed(evt);
        }
    });

    detailsPanel.setBackground(new java.awt.Color(204, 204, 204));
    detailsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Connection Settings",
            javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
    detailsPanel.setName("Connection Settings"); // NOI18N
    detailsPanel.setOpaque(false);

    hostLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    hostLabel.setText("SERVER ADDRESS");

    hostField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    hostField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    hostField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            hostFieldKeyPressed(evt);
        }
    });

    portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    portLabel.setText("SERVER PORT");

    portField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    portField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    portField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            portFieldKeyPressed(evt);
        }
    });

    dbCreateButton.setText("Create Database");
    dbCreateButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            dbCreateButtonActionPerformed(evt);
        }
    });

    databaseField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    databaseField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    databaseField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            databaseFieldKeyPressed(evt);
        }
    });

    databaseLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    databaseLabel.setText("DATABASE NAME");

    dbRemoveButton.setText("Remove Database");
    dbRemoveButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            dbRemoveButtonActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel);
    detailsPanel.setLayout(detailsPanelLayout);
    detailsPanelLayout.setHorizontalGroup(detailsPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(databaseLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(detailsPanelLayout.createSequentialGroup().addContainerGap().addGroup(detailsPanelLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(hostLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(hostField).addComponent(portField)
                    .addComponent(portLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                            Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                            detailsPanelLayout.createSequentialGroup().addComponent(dbRemoveButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(dbCreateButton))
                    .addComponent(databaseField, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addContainerGap()));
    detailsPanelLayout.setVerticalGroup(detailsPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(detailsPanelLayout.createSequentialGroup().addComponent(hostLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(databaseLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(databaseField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(dbCreateButton).addComponent(dbRemoveButton))));

    loginButton.setBackground(new java.awt.Color(0, 0, 0));
    loginButton.setText("Log In");
    loginButton.putClientProperty("JButton.buttonType", "textured");
    loginButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            loginButtonActionPerformed(evt);
        }
    });

    progressSigningIn.setIndeterminate(true);

    javax.swing.GroupLayout titlePanelLayout = new javax.swing.GroupLayout(titlePanel);
    titlePanel.setLayout(titlePanelLayout);
    titlePanelLayout.setHorizontalGroup(titlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(versionLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(spiralPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
            .addComponent(detailsPanel, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(titlePanelLayout.createSequentialGroup()
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(userLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(titlePanelLayout.createSequentialGroup().addContainerGap()
                                    .addGroup(titlePanelLayout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(button_settings).addComponent(userField,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 201,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(0, 0, Short.MAX_VALUE)))
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(titlePanelLayout.createSequentialGroup().addGap(6, 6, 6).addComponent(
                                    passwordLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, titlePanelLayout
                                    .createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(titlePanelLayout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                    titlePanelLayout.createSequentialGroup()
                                                            .addComponent(progressSigningIn,
                                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                                            .addPreferredGap(
                                                                    javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                            .addComponent(loginButton))
                                            .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    197, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addContainerGap()))));
    titlePanelLayout.setVerticalGroup(titlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, titlePanelLayout.createSequentialGroup()
                    .addComponent(spiralPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(versionLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userLabel).addComponent(passwordLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(loginButton)
                            .addComponent(progressSigningIn, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(button_settings))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(detailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(45, 45, 45, 45);
    add(titlePanel, gridBagConstraints);
}

From source file:org.ut.biolab.medsavant.client.view.Menu.java

public void addSection(SectionView section) {

    final JPanel sectionPanel = ViewUtil.getClearPanel();
    sectionPanel.setLayout(new BoxLayout(sectionPanel, BoxLayout.Y_AXIS));
    sectionPanel.setVisible(false);//from  w w w.jav  a  2  s.c  o  m

    //HoverButton sectionButton = new SectionButton(section, sectionPanel);
    //sectionButton.setSelectedColor(ViewUtil.getSecondaryMenuColor());

    final JToggleButton sectionButton = ViewUtil.getTogglableIconButton(section.getIcon());
    sectionButton.setName(section.getName());
    sectionButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    sectionButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            primaryMenuButtons.setSelected(sectionButton.getModel(), true);
            if (previousSectionPanel != null) {
                previousSectionPanel.setVisible(false);
            }
            // Act as if we clicked the first sub-section button.
            ((SubSectionButton) sectionPanel.getComponent(0)).subSectionClicked();
            sectionPanel.setVisible(true);

            previousSectionPanel = sectionPanel;
            primaryMenu.invalidate();
        }
    });

    ButtonGroup subSectionsGroup = new ButtonGroup();

    for (SubSectionView v : section.getSubSections()) {
        subSectionViews.add(v);

        SubSectionButton subSectionButton = new SubSectionButton(v, subSectionsGroup);
        sectionPanel.add(subSectionButton);
        subSectionsGroup.add(subSectionButton);

        map.put(v, subSectionButton);
    }

    primaryMenuButtons.add(sectionButton);

    sectionPanel.add(Box.createVerticalStrut(50));

    secondaryMenu.add(sectionPanel);

    primaryMenuSectionButtonContainer.add(ViewUtil.subTextComponent(sectionButton, section.getName()));
    primaryMenuSectionButtonContainer.add(ViewUtil.getLargeSeparator());

}

From source file:org.zaproxy.zap.extension.httppanel.HttpPanel.java

private void addComponent(HttpPanelComponentInterface component) {
    synchronized (components) {
        final String componentName = component.getName();
        if (components.containsKey(componentName)) {
            removeComponent(componentName);
        }/*  ww  w . ja  v  a  2 s.  com*/

        component.setEditable(isEditable);
        component.setEnableViewSelect(isEnableViewSelect);

        components.put(componentName, component);
        panelContent.add(component.getMainPanel(), componentName);

        final JToggleButton button = component.getButton();
        button.setActionCommand(componentName);

        button.addActionListener(getSwitchComponentItemListener());
        button.setEnabled(isEnableViewSelect);

        if (component.isEnabled(message)) {
            enableComponent(component);

            if (currentComponent == null) {
                switchComponent(componentName);
            } else if (savedLastSelectedComponentName != null
                    && savedLastSelectedComponentName.equals(componentName)) {
                switchComponent(componentName);
            } else if (savedLastSelectedComponentName == null
                    && currentComponent.getPosition() > component.getPosition()) {
                switchComponent(componentName);
            }
        }
    }
}

From source file:sk.stuba.fiit.kvasnicka.topologyvisual.gui.components.TopologyPalette.java

public void addChild(String category, String name, final PaletteActionEnum palSelEnum) {
    if (StringUtils.isEmpty(category)) {
        throw new IllegalArgumentException("category name is empty or NULL");
    }/*w  w  w.ja v a  2  s  .com*/

    if (!categories.containsKey(category)) {
        addCategory(category);
    }
    JXTaskPane taskPane = categories.get(category);
    final JToggleButton btn = new JToggleButton(name);
    taskPane.add(btn);
    btn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (isSelectedButton()) {
                selected.setSelected(false);
            }
            selected = btn;
            if (selected.isSelected()) {
                firePaletteSelectedOccurred(new PaletteSelectionEvent(this, palSelEnum));
            } else {
                firePaletteDeselectedOccurred(new PaletteSelectionEvent(this, palSelEnum));
            }
        }
    });
}