Example usage for javax.swing JButton setActionCommand

List of usage examples for javax.swing JButton setActionCommand

Introduction

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

Prototype

public void setActionCommand(String actionCommand) 

Source Link

Document

Sets the action command for this button.

Usage

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);/*from w  w w  . ja va2  s  .co 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:org.ietr.preesm.mapper.ui.BestCostPlotter.java

/**
 * Constructs the latency plotter/*from www  .j  ava2s . co m*/
 * 
 * @param title
 *            the frame title.
 */
public BestCostPlotter(final String title, Semaphore pauseSemaphore) {

    super(title);

    JFreeChart chart = createChart(title);
    final JPanel content = new JPanel(new BorderLayout());

    chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());

    final JButton buttonPause = new JButton("Pause");
    buttonPause.setActionCommand("pause");
    buttonPause.addActionListener(this);
    buttonPanel.add(buttonPause);

    final JButton buttonAll = new JButton("Stop");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    final JButton buttonLecture = new JButton("Resume");
    buttonLecture.setActionCommand("Resume");
    buttonLecture.addActionListener(this);
    buttonPanel.add(buttonLecture);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    this.pauseSemaphore = pauseSemaphore;
}

From source file:com.game.ui.views.WeaponEditorPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel(
            "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new "
                    + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);//  w  w w.  ja  va 2  s.  c om
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            model.addElement(((Weapon) item).getName());
        }
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel weaponDtsLbl = new JLabel("Weapon Details : ");
    weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(weaponDtsLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel weaponTypeLbl = new JLabel("Weapon Type : ");
    panel1.add(weaponTypeLbl, c);
    c.gridx = 1;
    JComboBox weaponType = new JComboBox(Configuration.weaponTypes);
    weaponType.setSelectedIndex(0);
    weaponType.setPreferredSize(name.getPreferredSize());
    System.out.println(name.getPreferredSize());
    panel1.add(weaponType, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel attackRangeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRangeLbl, c);
    c.gridx = 1;
    JTextField attackRange = new JTextField("");
    attackRange.setColumns(20);
    panel1.add(attackRange, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.weighty = 0;
    c.weightx = 1;
    validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    panel1.add(validationMess, c);
    //        c.fill = GridBagConstraints.BOTH;
    //        c.gridy = 7;
    //        c.weightx = 1;
    //        c.weighty = 1;
    //        panel1.add(new JLabel(""), c);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    add(panel1);
    add(Box.createVerticalGlue());
}

From source file:LineTypes.java

JPanel guiPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(0, 1));

    if (isApplication) {
        JButton snapButton = new JButton(snapImageString);
        snapButton.setActionCommand(snapImageString);
        snapButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                doSnapshot();/*from  w w  w  . j  av a 2  s  .com*/
            }
        });
        panel.add(snapButton);
    }

    return panel;
}

From source file:edu.harvard.mcz.imagecapture.TemplatePickerDialog.java

protected void init(ICImage image) {
    setBounds(100, 100, 450, 300);//from  www .  ja  v a2  s  . com
    StringBuffer title = new StringBuffer();
    title.append("Change Template");
    if (image != null) {
        title.append(" for ").append(image.getFilename());
    }
    this.setTitle(title.toString());
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        lblTemplate = new JLabel("Template");
        lblTemplate.setHorizontalAlignment(SwingConstants.CENTER);
        contentPanel.add(lblTemplate, BorderLayout.NORTH);
    }
    {
        comboBoxTemplatePicker = new JComboBox<String>();
        comboBoxTemplatePicker.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                PositionTemplate defaultTemplate;
                try {
                    defaultTemplate = new PositionTemplate((String) comboBoxTemplatePicker.getSelectedItem());

                    File fileToCheck = new File(ImageCaptureProperties
                            .assemblePathWithBase(imageToTemplate.getPath(), imageToTemplate.getFilename()));

                    BufferedImage imagefile = ImageIO.read(fileToCheck);

                    int x = defaultTemplate.getBarcodeULPosition().width;
                    int y = defaultTemplate.getBarcodeULPosition().height;
                    int w = defaultTemplate.getBarcodeSize().width;
                    int h = defaultTemplate.getBarcodeSize().height;
                    setBarcodeImage(imagefile.getSubimage(x, y, w, h));

                } catch (NullPointerException e1) {
                    log.error(e1.getMessage());
                } catch (NoSuchTemplateException e1) {
                    log.error(e1.getMessage());
                } catch (IOException e1) {
                    log.error(e1.getMessage());
                }
            }

        });
        contentPanel.add(comboBoxTemplatePicker, BorderLayout.SOUTH);
    }
    {
        JPanel panel = new JPanel();
        contentPanel.add(panel, BorderLayout.CENTER);
        panel.setLayout(new BorderLayout(0, 0));
        {
            lblFileName = new JLabel("FileName");
            panel.add(lblFileName, BorderLayout.NORTH);
        }
        {
            labelBarcodeImage = new JLabel("Catalog Number Barcode");
            labelBarcodeImage.setIcon(new ImageIcon(TemplatePickerDialog.class
                    .getResource("/edu/harvard/mcz/imagecapture/resources/gnome-mime-image.png")));
            panel.add(labelBarcodeImage, BorderLayout.CENTER);
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("OK");
            okButton.setActionCommand("OK");
            okButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    ICImageLifeCycle ils = new ICImageLifeCycle();
                    try {
                        String newTemplateID = (String) comboBoxTemplatePicker.getSelectedItem();
                        if (newTemplateID != null) {
                            imageToTemplate.setTemplateId(newTemplateID);
                            ils.attachDirty(imageToTemplate);
                            setVisible(false);
                        }
                    } catch (SaveFailedException e1) {
                        log.error(e1.getMessage(), e1);
                    }
                }

            });
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.setActionCommand("Cancel");
            cancelButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }

            });
            buttonPane.add(cancelButton);
        }
    }
    if (image != null) {
        try {
            boolean result = setupForImage(image);
        } catch (UnreadableFileException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.game.ui.views.CharachterEditorPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel("Pls select a value to choose an enemy or you can create a new "
            + "Enemy entity below. Once selected an Enemy character, its' details will be available below");
    noteLbl.setAlignmentX(0);//from  w  ww .ja  va2s.  c  o m
    //        noteLbl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.enemyDetails) {
        System.out.println(character.getName());
        model.addElement(character.getName());
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    panel1.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    panel1.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    panel1.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    panel1.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    panel1.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    panel1.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    panel1.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    panel1.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    panel1.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    add(panel1);
    c.gridx = 0;
    c.gridy = 9;
    JLabel validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    add(validationMess, c);
    add(Box.createVerticalGlue());
}

From source file:com.haskins.cloudtrailviewer.feature.MetricsFeature.java

private void addButton(String service) {

    JButton btn = new JButton(service);
    btn.addActionListener(this);
    btn.setActionCommand(service);

    toolbar.add(btn);/*w  w w.  ja v  a  2s  .  c om*/
}

From source file:com.game.ui.views.PlayerEditor.java

public void doGui() {
    //        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new GridBagLayout());
    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.NONE;
    c1.anchor = GridBagConstraints.WEST;
    c1.insets = new Insets(10, 5, 10, 5);
    c1.weightx = 0;//  w w  w.  j a  va2  s.  co  m
    c1.weighty = 0;
    JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new "
            + "Player entity below. Once selected a Player character, its' details will be available below");
    add(noteLbl, c1);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.playerDetails) {
        model.addElement(((Player) character).getType());
    }
    c1.gridy = 1;
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(comboBox, c1);
    JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10));
    wrapperPanel.setBorder(LineBorder.createGrayLineBorder());
    leftPanel = new JPanel();
    leftPanel.setAlignmentX(0);
    leftPanel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    leftPanel.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    leftPanel.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    leftPanel.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    leftPanel.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    leftPanel.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    leftPanel.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    leftPanel.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    leftPanel.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    leftPanel.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    leftPanel.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    leftPanel.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    leftPanel.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    leftPanel.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    leftPanel.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    leftPanel.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    JLabel typeLbl = new JLabel("Type : ");
    leftPanel.add(typeLbl, c);
    c.gridx = 1;
    JTextField typeTxt = new JTextField("");
    typeTxt.setColumns(20);
    leftPanel.add(typeTxt, c);
    c.gridx = 0;
    c.gridy = 9;
    JLabel weaponLbl = new JLabel("Equipped Weapon : ");
    leftPanel.add(weaponLbl, c);
    c.gridx = 1;
    DefaultComboBoxModel weapon = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            weapon.addElement(((Weapon) item).getName());
        }
    }
    JComboBox weaponDrpDown = new JComboBox(weapon);
    weaponDrpDown.setSelectedIndex(-1);
    weaponDrpDown.setMaximumSize(new Dimension(100, 30));
    leftPanel.add(weaponDrpDown, c);
    c.gridx = 0;
    c.gridy = 10;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    leftPanel.add(submit, c);
    wrapperPanel.add(leftPanel);
    lvlPanel = new LevelPanel(true, null);
    wrapperPanel.add(lvlPanel);
    c1.gridy = 2;
    c1.fill = GridBagConstraints.BOTH;
    add(wrapperPanel, c1);
    c1.fill = GridBagConstraints.NONE;
    validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    c1.gridy = 3;
    add(validationMess, c1);
    c1.weightx = 1;
    c1.fill = GridBagConstraints.BOTH;
    c1.weighty = 1;
    c1.gridy = 4;
    add(new JPanel(), c1);
}

From source file:com.hexidec.ekit.component.UnicodeDialog.java

public void init(int startIndex) {
    String customFont = Translatrix.getTranslationString("UnicodeDialogButtonFont");
    if (customFont != null && customFont.length() > 0) {
        buttonFont = new Font(Translatrix.getTranslationString("UnicodeDialogButtonFont"), Font.PLAIN, 12);
    } else {//from   w  w  w . j a  va 2s.c  o  m
        buttonFont = new Font("Monospaced", Font.PLAIN, 12);
    }

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 17, 0, 0));
    buttonGroup = new ButtonGroup();

    int prefButtonWidth = 32;
    int prefButtonHeight = 32;

    centerPanel.add(new JLabel(""));
    for (int labelLoop = 0; labelLoop < 16; labelLoop++) {
        JLabel jlblMarker = new JLabel(
                "x" + (labelLoop > 9 ? "" + (char) (65 + (labelLoop - 10)) : "" + labelLoop));
        jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
        jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
        jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
        centerPanel.add(jlblMarker);
    }

    int labelcount = 0;
    for (int counter = 0; counter < UNICODEBLOCKSIZE; counter++) {
        if ((counter % 16) == 0) {
            JLabel jlblMarker = new JLabel(
                    (labelcount > 9 ? "" + (char) (65 + (labelcount - 10)) : "" + labelcount) + "x");
            jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
            jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
            jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
            centerPanel.add(jlblMarker);
            labelcount++;
        }
        buttonArray[counter] = new JToggleButton(" ");
        buttonArray[counter].getModel().setActionCommand("");
        buttonArray[counter].setFont(buttonFont);
        buttonArray[counter].setBorder(
                javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
        buttonArray[counter].addActionListener(this);
        if (counter == 0) {
            FontRenderContext frcLocal = ((java.awt.Graphics2D) (parentEkit.getGraphics()))
                    .getFontRenderContext();
            Rectangle2D fontBounds = buttonFont.getMaxCharBounds(frcLocal);
            int maxCharWidth = (int) (Math.abs(fontBounds.getX())) + (int) (Math.abs(fontBounds.getWidth()));
            int maxCharHeight = (int) (Math.abs(fontBounds.getY())) + (int) (Math.abs(fontBounds.getHeight()));
            Insets buttonInsets = buttonArray[counter].getBorder().getBorderInsets(buttonArray[counter]);
            prefButtonWidth = maxCharWidth + buttonInsets.left + buttonInsets.right;
            prefButtonHeight = maxCharHeight + buttonInsets.top + buttonInsets.bottom;
        }
        buttonArray[counter].setPreferredSize(new Dimension(prefButtonWidth, prefButtonHeight));
        centerPanel.add(buttonArray[counter]);
        buttonGroup.add(buttonArray[counter]);
    }

    JPanel selectorPanel = new JPanel();

    jcmbBlockSelector = new JComboBox(unicodeBlocks);
    jcmbBlockSelector.setSelectedIndex(startIndex);
    jcmbBlockSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbBlockSelector.addActionListener(this);

    String[] sPages = { "1" };
    jcmbPageSelector = new JComboBox(sPages);
    jcmbPageSelector.setSelectedIndex(0);
    jcmbPageSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbPageSelector.addActionListener(this);

    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodeBlock")));
    selectorPanel.add(jcmbBlockSelector);
    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodePage")));
    selectorPanel.add(jcmbPageSelector);

    JPanel buttonPanel = new JPanel();

    JButton closeButton = new JButton(Translatrix.getTranslationString("DialogClose"));
    closeButton.setActionCommand("close");
    closeButton.addActionListener(this);
    buttonPanel.add(closeButton);

    contentPane.add(centerPanel, BorderLayout.CENTER);
    contentPane.add(selectorPanel, BorderLayout.NORTH);
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    this.pack();

    populateButtons(startIndex, 0);

    this.setVisible(true);
}

From source file:br.com.criativasoft.opendevice.samples.ui.SimpleChart.java

public SimpleChart(final String title, final StreamConnection connection) {
    super(title);

    dataset = new DynamicTimeSeriesCollection(SERIES, COUNT, new Second());
    dataset.setTimeBase(new Second(0, 0, 0, 1, 1, Calendar.getInstance().get(Calendar.YEAR)));

    // Init.//from   w ww .j av a 2  s.c o m
    //        for (int i = 0; i < SERIES; i++){
    //            dataset.addSeries(new float[]{0}, i, "Serie " + (i+1));
    //        }
    dataset.addSeries(new float[] { 0, 0, 0 }, 0, "Raw");
    dataset.addSeries(new float[] { 0, 0, 0 }, 1, "Software");
    dataset.addSeries(new float[] { 0, 0, 0 }, 2, "Hardware");

    this.connection = connection;

    // connection.setStreamReader(new FixedStreamReader(1));

    JFreeChart chart = createChart(dataset);

    final JButton run = new JButton(START);
    run.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            String cmd = e.getActionCommand();
            JButton source = (JButton) e.getSource();

            try {

                if (cmd.equals(START)) {
                    connection.addListener(SimpleChart.this);
                    if (!connection.isConnected())
                        connection.connect();

                    source.setText(STOP);
                    source.setActionCommand(STOP);
                } else {
                    connection.removeListener(SimpleChart.this);
                    source.setText(START);
                    source.setActionCommand(START);
                }

            } catch (ConnectionException e1) {
                e1.printStackTrace();
            }

        }
    });

    final JComboBox combo = new JComboBox();

    if (connection instanceof UsbConnection) {

        Collection<String> portNames = UsbConnection.listAvailablePortNames();
        for (String name : portNames) {
            combo.addItem(name);
        }

    }

    combo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Object selectedItem = combo.getSelectedItem();

        }
    });

    this.add(new ChartPanel(chart), BorderLayout.CENTER);
    JPanel btnPanel = new JPanel(new FlowLayout());
    btnPanel.add(run);
    btnPanel.add(combo);
    this.add(btnPanel, BorderLayout.SOUTH);

}