Example usage for javax.swing JList JList

List of usage examples for javax.swing JList JList

Introduction

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

Prototype

public JList() 

Source Link

Document

Constructs a JList with an empty, read-only, model.

Usage

From source file:Accounts.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    accountNumberList = new JList();
    loadAccounts();//from w  ww. jav  a2s  .c  o m
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                ResultSet rs = statement.executeQuery(
                        "SELECT * FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
                if (rs.next()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    usernameText.setText(rs.getString("username"));
                    passwordText.setText(rs.getString("password"));
                    tsText.setText(rs.getString("ts"));
                    activeTSText.setText(rs.getString("act_ts"));
                }
            } catch (SQLException selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("INSERT INTO acc_acc VALUES(" + accountIDText.getText() + ", "
                        + "'" + usernameText.getText() + "', " + "'" + passwordText.getText() + "', " + "0"
                        + ", " + "now())");
                errorText.append("Inserted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Delete Account Button
    deleteAccountButton = new JButton("Delete Account");
    deleteAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate(
                        "DELETE FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Deleted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("UPDATE acc_acc " + "SET username='" + usernameText.getText()
                        + "', " + "password='" + passwordText.getText() + "', " + "act_ts = now() "
                        + "WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Updated " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    JPanel first = new JPanel(new GridLayout(5, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(insertAccountButton);
    first.add(deleteAccountButton);
    first.add(updateAccountButton);

    accountIDText = new JTextField(15);
    usernameText = new JTextField(15);
    passwordText = new JTextField(15);
    tsText = new JTextField(15);
    activeTSText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(6, 1));
    second.add(accountIDText);
    second.add(usernameText);
    second.add(passwordText);
    second.add(tsText);
    second.add(activeTSText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    c.add(first);
    c.add(second);
    c.add(third);
    setSize(500, 500);
    show();
}

From source file:RSAccounts.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    accountNumberList = new JList();
    loadAccounts();//from w  ww .  ja  va  2 s. c o  m
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    gotoText = new JTextField(3);
    freeQueryText = new JTextField(40);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.first();
                while (rs.next()) {
                    if (rs.getString("acc_id").equals(accountNumberList.getSelectedValue()))
                        break;
                }
                if (!rs.isAfterLast()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    usernameText.setText(rs.getString("username"));
                    passwordText.setText(rs.getString("password"));
                    tsText.setText(rs.getString("ts"));
                    activeTSText.setText(rs.getString("act_ts"));
                }
            } catch (SQLException selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("INSERT INTO acc_acc VALUES(" + accountIDText.getText() + ", "
                        + "'" + usernameText.getText() + "', " + "'" + passwordText.getText() + "', " + "0"
                        + ", " + "now())");
                errorText.append("Inserted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Delete Account Button
    deleteAccountButton = new JButton("Delete Account");
    deleteAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate(
                        "DELETE FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Deleted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("UPDATE acc_acc " + "SET username='" + usernameText.getText()
                        + "', " + "password='" + passwordText.getText() + "', " + "act_ts = now() "
                        + "WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Updated " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Next Button
    nextButton = new JButton(">");
    nextButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                if (!rs.isLast()) {
                    rs.next();
                    accountIDText.setText(rs.getString("acc_id"));
                    usernameText.setText(rs.getString("username"));
                    passwordText.setText(rs.getString("password"));
                    tsText.setText(rs.getString("ts"));
                    activeTSText.setText(rs.getString("act_ts"));
                }
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Next Button
    previousButton = new JButton("<");
    previousButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                if (!rs.isFirst()) {
                    rs.previous();
                    accountIDText.setText(rs.getString("acc_id"));
                    usernameText.setText(rs.getString("username"));
                    passwordText.setText(rs.getString("password"));
                    tsText.setText(rs.getString("ts"));
                    activeTSText.setText(rs.getString("act_ts"));
                }
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do last Button
    lastButton = new JButton(">|");
    lastButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.last();
                accountIDText.setText(rs.getString("acc_id"));
                usernameText.setText(rs.getString("username"));
                passwordText.setText(rs.getString("password"));
                tsText.setText(rs.getString("ts"));
                activeTSText.setText(rs.getString("act_ts"));
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do first Button
    firstButton = new JButton("|<");
    firstButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.first();
                accountIDText.setText(rs.getString("acc_id"));
                usernameText.setText(rs.getString("username"));
                passwordText.setText(rs.getString("password"));
                tsText.setText(rs.getString("ts"));
                activeTSText.setText(rs.getString("act_ts"));
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do gotoButton
    gotoButton = new JButton("Goto");
    gotoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.absolute(Integer.parseInt(gotoText.getText()));
                accountIDText.setText(rs.getString("acc_id"));
                usernameText.setText(rs.getString("username"));
                passwordText.setText(rs.getString("password"));
                tsText.setText(rs.getString("ts"));
                activeTSText.setText(rs.getString("act_ts"));
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do freeQueryButton
    freeQueryButton = new JButton("Execute Query");
    freeQueryButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                if (freeQueryText.getText().toUpperCase().indexOf("SELECT") >= 0) {
                    rs = statement.executeQuery(freeQueryText.getText());
                    if (rs.next()) {
                        accountIDText.setText(rs.getString("acc_id"));
                        usernameText.setText(rs.getString("username"));
                        passwordText.setText(rs.getString("password"));
                        tsText.setText(rs.getString("ts"));
                        activeTSText.setText(rs.getString("act_ts"));
                    }
                } else {
                    int i = statement.executeUpdate(freeQueryText.getText());
                    errorText.append("Rows affected = " + i);
                    loadAccounts();
                }
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    JPanel first = new JPanel(new GridLayout(5, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(insertAccountButton);
    first.add(deleteAccountButton);
    first.add(updateAccountButton);

    accountIDText = new JTextField(15);
    usernameText = new JTextField(15);
    passwordText = new JTextField(15);
    tsText = new JTextField(15);
    activeTSText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(6, 1));
    second.add(accountIDText);
    second.add(usernameText);
    second.add(passwordText);
    second.add(tsText);
    second.add(activeTSText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    JPanel fourth = new JPanel();
    fourth.add(firstButton);
    fourth.add(previousButton);
    fourth.add(nextButton);
    fourth.add(lastButton);
    fourth.add(gotoText);
    fourth.add(gotoButton);

    JPanel fifth = new JPanel();
    fifth.add(freeQueryText);

    c.add(first);
    c.add(second);
    c.add(third);
    c.add(fourth);
    c.add(fifth);
    c.add(freeQueryButton);
    setSize(500, 500);
    show();
}

From source file:IDlook.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    accountNumberList = new JList();
    loadAccounts();//from   www.  j av  a 2  s .com
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.beforeFirst();
                while (rs.next()) {
                    if (rs.getString("acc_id").equals(accountNumberList.getSelectedValue()))
                        break;
                }
                if (!rs.isAfterLast()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    thumbIDText.setText(rs.getString("thumb_id"));

                    icon = new ImageIcon(rs.getBytes("pic"));
                    createThumbnail();
                    photographLabel.setIcon(iconThumbnail);
                }
            } catch (SQLException selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.updateBytes("thumbnail.pic", bytes);
                rs.updateRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    //Do insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.moveToInsertRow();
                rs.updateInt("thumb_id", Integer.parseInt(thumbIDText.getText()));
                rs.updateInt("acc_id", Integer.parseInt(accountIDText.getText()));
                rs.updateBytes("pic", bytes);
                rs.updateObject("sysobject", null);
                rs.updateTimestamp("ts", new Timestamp(0));
                rs.updateTimestamp("act_ts", new Timestamp(new java.util.Date().getTime()));
                rs.insertRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    photographLabel = new JLabel();
    photographLabel.setHorizontalAlignment(JLabel.CENTER);
    photographLabel.setVerticalAlignment(JLabel.CENTER);
    photographLabel.setVerticalTextPosition(JLabel.CENTER);
    photographLabel.setHorizontalTextPosition(JLabel.CENTER);

    JPanel first = new JPanel(new GridLayout(4, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(updateAccountButton);
    first.add(insertAccountButton);

    accountIDText = new JTextField(15);
    thumbIDText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(2, 1));
    second.add(thumbIDText);
    second.add(accountIDText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    nailFileText = new JTextField(25);

    c.add(first);
    c.add(second);
    c.add(third);
    c.add(nailFileText);
    c.add(photographLabel);

    setSize(500, 500);
    show();
}

From source file:IDlookBlob.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    accountNumberList = new JList();
    loadAccounts();/*from   w w  w  .j  a v a2s.  c o m*/
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.beforeFirst();
                while (rs.next()) {
                    if (rs.getString("acc_id").equals(accountNumberList.getSelectedValue()))
                        break;
                }
                if (!rs.isAfterLast()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    thumbIDText.setText(rs.getString("thumb_id"));
                    Blob b = rs.getBlob("pic");

                    icon = new ImageIcon(b.getBytes(1L, (int) b.length()));
                    createThumbnail();
                    photographLabel.setIcon(iconThumbnail);
                }
            } catch (SQLException selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.updateBytes("thumbnail.pic", bytes);
                rs.updateRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    //Do insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.moveToInsertRow();
                rs.updateInt("thumb_id", Integer.parseInt(thumbIDText.getText()));
                rs.updateInt("acc_id", Integer.parseInt(accountIDText.getText()));
                rs.updateBytes("pic", bytes);
                rs.updateObject("sysobject", null);
                rs.updateTimestamp("ts", new Timestamp(0));
                rs.updateTimestamp("act_ts", new Timestamp(new java.util.Date().getTime()));
                rs.insertRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    photographLabel = new JLabel();
    photographLabel.setHorizontalAlignment(JLabel.CENTER);
    photographLabel.setVerticalAlignment(JLabel.CENTER);
    photographLabel.setVerticalTextPosition(JLabel.CENTER);
    photographLabel.setHorizontalTextPosition(JLabel.CENTER);

    JPanel first = new JPanel(new GridLayout(4, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(updateAccountButton);
    first.add(insertAccountButton);

    accountIDText = new JTextField(15);
    thumbIDText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(2, 1));
    second.add(thumbIDText);
    second.add(accountIDText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    nailFileText = new JTextField(25);

    c.add(first);
    c.add(second);
    c.add(third);
    c.add(nailFileText);
    c.add(photographLabel);

    setSize(500, 500);
    show();
}

From source file:IDlookGetStream.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    accountNumberList = new JList();
    loadAccounts();// w  ww .  j  a va2s .c  o  m
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                rs.beforeFirst();
                while (rs.next()) {
                    if (rs.getString("acc_id").equals(accountNumberList.getSelectedValue()))
                        break;
                }
                if (!rs.isAfterLast()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    thumbIDText.setText(rs.getString("thumb_id"));
                    Blob blob = rs.getBlob("pic");

                    int b;
                    InputStream bis = rs.getBinaryStream("pic");
                    FileOutputStream f = new FileOutputStream("pic.jpg");
                    while ((b = bis.read()) >= 0) {
                        f.write(b);
                    }
                    f.close();
                    bis.close();

                    icon = new ImageIcon(blob.getBytes(1L, (int) blob.length()));
                    createThumbnail();
                    photographLabel.setIcon(iconThumbnail);
                }
            } catch (Exception selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.updateBytes("thumbnail.pic", bytes);
                rs.updateRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    //Do insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                byte[] bytes = new byte[50000];
                FileInputStream fs = new FileInputStream(nailFileText.getText());
                BufferedInputStream bis = new BufferedInputStream(fs);
                bis.read(bytes);

                rs.moveToInsertRow();
                rs.updateInt("thumb_id", Integer.parseInt(thumbIDText.getText()));
                rs.updateInt("acc_id", Integer.parseInt(accountIDText.getText()));
                rs.updateBytes("pic", bytes);
                rs.updateObject("sysobject", null);
                rs.updateTimestamp("ts", new Timestamp(0));
                rs.updateTimestamp("act_ts", new Timestamp(new java.util.Date().getTime()));
                rs.insertRow();
                bis.close();

                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            } catch (Exception generalE) {
                generalE.printStackTrace();
            }
        }
    });

    photographLabel = new JLabel();
    photographLabel.setHorizontalAlignment(JLabel.CENTER);
    photographLabel.setVerticalAlignment(JLabel.CENTER);
    photographLabel.setVerticalTextPosition(JLabel.CENTER);
    photographLabel.setHorizontalTextPosition(JLabel.CENTER);

    JPanel first = new JPanel(new GridLayout(4, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(updateAccountButton);
    first.add(insertAccountButton);

    accountIDText = new JTextField(15);
    thumbIDText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(2, 1));
    second.add(thumbIDText);
    second.add(accountIDText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    nailFileText = new JTextField(25);

    c.add(first);
    c.add(second);
    c.add(third);
    c.add(nailFileText);
    c.add(photographLabel);

    setSize(500, 500);
    show();
}

From source file:AliasBean.java

public AliasBean() {
    aliVector = new Vector();
    aliJList = new JList();
    // XXX MUST FIX THIS
    // aliJList.setSelectionMode(JList.SINGLE_SELECTION);
    aliJList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            int i = aliJList.getSelectedIndex();
            if (i < 0)
                return;
            Alias al = (Alias) aliVector.get(i);
            nameTF.setText(al.getName());
            addrTF.setText(al.getAddress());
        }/*from w  w  w  . j a  v  a2 s  .c  om*/
    });

    setLayout(new BorderLayout());
    add(BorderLayout.WEST, new JScrollPane(aliJList));

    JPanel rightPanel = new JPanel();
    add(BorderLayout.EAST, rightPanel);
    rightPanel.setLayout(new GridLayout(0, 1));

    JPanel buttons = new JPanel();
    rightPanel.add(buttons);
    buttons.setLayout(new GridLayout(0, 1, 15, 15));
    JButton b;
    buttons.add(b = new JButton("Set"));
    b.setToolTipText("Add or Change an alias");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            int i = aliJList.getSelectedIndex();
            if (i < 0) {
                // XXX error dialog??
                return;
            }
            setAlias(i, nameTF.getText(), addrTF.getText());
        }
    });
    buttons.add(b = new JButton("Delete"));
    b.setToolTipText("Delete the selected alias");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            int i = aliJList.getSelectedIndex();
            if (i < 0) {
                return;
            }
            deleteAlias(i);
        }
    });
    buttons.add(b = new JButton("Apply"));
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.err.println("NOT WRITTEN YET");
        }
    });

    JPanel fields = new JPanel();
    rightPanel.add(fields);
    fields.setLayout(new GridLayout(2, 2));
    fields.add(new JLabel("Name"));
    fields.add(nameTF = new JTextField(10));
    fields.add(new JLabel("Address"));
    fields.add(addrTF = new JTextField(20));
}

From source file:gtu._work.ui.StringArrayMakerUI.java

private void initGUI() {
    try {// ww w .  ja  va2 s  . co m
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(525, 267));
                    {
                        ListModel jList1Model = new DefaultListModel();
                        jList1 = new JList();

                        jScrollPane2.setViewportView(jList1);
                        jList1.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jList1).defaultJListKeyPressed(evt);
                            }
                        });
                        jList1.setModel(jList1Model);
                    }
                }
                {
                    jButton1 = new JButton();
                    jPanel1.add(jButton1, BorderLayout.NORTH);
                    jButton1.setText("\u8cbc\u4e0a");
                    jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    FlowLayout jPanel3Layout = new FlowLayout();
                    jPanel3Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel1.add(jPanel3, BorderLayout.WEST);
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel3.setPreferredSize(new java.awt.Dimension(50, 291));
                    {
                        jCheckBox1 = new JCheckBox();
                        jPanel3.add(jCheckBox1);
                        jCheckBox1.setText("\\n");
                    }
                    {
                        jCheckBox2 = new JCheckBox();
                        jPanel3.add(jCheckBox2);
                        jCheckBox2.setText("\\t");
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
                {
                    jButton2 = new JButton();
                    jPanel2.add(jButton2, BorderLayout.NORTH);
                    jButton2.setText("\u7522\u751f");
                    jButton2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton2ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(525, 291));
                    {
                        jTextArea1 = new JTextArea();
                        jScrollPane1.setViewportView(jTextArea1);
                        jTextArea1.setText("");
                    }
                }
            }
        }
        pack();
        this.setSize(546, 382);
    } catch (Exception e) {
        // add your error handling code here
        e.printStackTrace();
    }
}

From source file:com.iisigroup.ris.WebFileScanUtilBrowserUI.java

private void initGUI() {
    final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
    try {/*w ww  .j a  va 2 s .  c om*/
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("browser source code");
        {
            informationMenu = new JPopupMenu();
            setComponentPopupMenu(this, informationMenu);
        }
        {
            ListModel openFileListModel = new DefaultListModel();
            openFileList = new JList();
            openFileList.setModel(openFileListModel);
            getContentPane().add(openFileList, BorderLayout.NORTH);
            openFileList.setPreferredSize(new java.awt.Dimension(663, 281));
            openFileList.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    swingUtil.invokeAction("openFileList.valueChanged", evt);
                }
            });
            openFileList.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseMoved(MouseEvent evt) {
                    swingUtil.invokeAction("openFileList.mouseMoved", evt);
                }
            });
            openFileList.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent evt) {
                    swingUtil.invokeAction("openFileList.keyPressed", evt);
                }
            });
        }
        {
            jPanel1 = new JPanel();
            GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.SOUTH);
            jPanel1.setPreferredSize(new java.awt.Dimension(478, 35));
            {
                openSelected = new JButton();
                openSelected.setText("open all");
                openSelected.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("openSelected.actionPerformed", evt);
                    }
                });
            }
            jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(178, 178)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(174, Short.MAX_VALUE));
            jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().addGap(7)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 6, Short.MAX_VALUE));
        }
        {
            informationMenu = new JPopupMenu();
        }

        this.setSize(486, 350);
        this.setLocationRelativeTo(null);

        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        int initialDelay = ToolTipManager.sharedInstance().getInitialDelay();
        ToolTipManager.sharedInstance().setInitialDelay(0);
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        swingUtil.addAction("openFileList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                int pos = openFileList.getLeadSelectionIndex();
                if (pos == -1) {
                    return;
                }
                setOpenFileListToolTip();
                MouseEvent eeev = (MouseEvent) evt;
                if (eeev.getClickCount() != 2) {
                    return;
                }
                MFile file = (MFile) model.elementAt(pos);
                openSource(file.file);
            }
        });
        final JListUtil jlistUtil = JListUtil.newInstance(openFileList);
        swingUtil.addAction("openFileList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                jlistUtil.defaultJListKeyPressed((KeyEvent) evt);
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openSelected.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    MFile file = (MFile) enu.nextElement();
                    openSource(file.file);
                }
            }
        });
        swingUtil.addAction("openFileList.mouseMoved", new Action() {
            public void action(EventObject evt) throws Exception {
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openFileList.valueChanged", new Action() {
            public void action(EventObject evt) throws Exception {
                System.out.println(evt);
                setOpenFileListToolTip();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:au.org.ala.delta.intkey.ui.OpenDataSetDialog.java

public OpenDataSetDialog(Frame owner, List<Pair<String, String>> datasetIndexData, File startBrowseDirectory) {
    super(owner, true);
    setPreferredSize(new Dimension(450, 300));

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);
    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(OpenDataSetDialog.class);
    resourceMap.injectFields(this);

    setTitle(title);//from ww w  . ja  v a 2 s  . c o m

    _selectedDatasetPath = null;

    _pnlList = new JPanel();
    _pnlList.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlList, BorderLayout.CENTER);
    _pnlList.setLayout(new BorderLayout(0, 0));

    _lblSelectByTitle = new JLabel(selectByTitleCaption);
    _pnlList.add(_lblSelectByTitle, BorderLayout.NORTH);

    _sclPnList = new JScrollPane();
    _pnlList.add(_sclPnList, BorderLayout.CENTER);

    _listDatasetIndex = new JList();
    _sclPnList.setViewportView(_listDatasetIndex);

    _pnlBottom = new JPanel();
    _pnlBottom.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlBottom, BorderLayout.SOUTH);
    _pnlBottom.setLayout(new BorderLayout(0, 0));

    _lblSelectByFileName = new JLabel(selectByFileCaption);
    _pnlBottom.add(_lblSelectByFileName, BorderLayout.NORTH);

    _pnlButtons = new JPanel();
    _pnlButtons.setBorder(new EmptyBorder(10, 0, 0, 0));
    _pnlBottom.add(_pnlButtons, BorderLayout.SOUTH);

    _btnOK = new JButton();
    _btnOK.setAction(actionMap.get("OpenDataSetDialog_OK"));
    _pnlButtons.add(_btnOK);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("OpenDataSetDialog_Cancel"));
    _pnlButtons.add(_btnCancel);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("OpenDataSetDialog_Help"));
    _pnlButtons.add(_btnHelp);

    _pnlFile = new JPanel();
    _pnlBottom.add(_pnlFile, BorderLayout.CENTER);
    _pnlFile.setLayout(new BorderLayout(0, 0));

    _txtFldFileName = new JTextField();
    _pnlFile.add(_txtFldFileName, BorderLayout.CENTER);
    _txtFldFileName.setColumns(10);
    _txtFldFileName.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            // Clear any selected item in the list of the text field is
            // modified.
            _listDatasetIndex.clearSelection();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // do nothing

        }
    });

    _btnBrowse = new JButton();
    _btnBrowse.setAction(actionMap.get("OpenDataSetDialog_Browse"));
    _pnlFile.add(_btnBrowse, BorderLayout.EAST);

    DefaultListModel model = new DefaultListModel();

    for (Pair<String, String> datasetInfo : datasetIndexData) {
        model.addElement(datasetInfo);
    }

    _listDatasetIndex.setModel(model);
    _listDatasetIndex.setCellRenderer(new DatasetIndexCellRenderer());

    _listDatasetIndex.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // Clear any filename in the text field if an item is selected
            // from the text box.
            _txtFldFileName.setText(null);
        }
    });

    _startBrowseDirectory = startBrowseDirectory;
}

From source file:dpcs.AppPackagesList.java

@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public AppPackagesList() {
    setResizable(false);/*from  ww w. jav  a2s  .  c o m*/
    setTitle("App Packages List");
    setIconImage(Toolkit.getDefaultToolkit().getImage(AppPackagesList.class.getResource("/graphics/Icon.png")));
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 479, 451);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(22, 12, 428, 333);
    contentPane.add(scrollPane);

    JButton btnRefresh = new JButton("Refresh");
    btnRefresh.setToolTipText("Refresh the apps list");
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Process p1 = Runtime.getRuntime().exec("adb shell pm list packages > /sdcard/.allapps.txt");
                p1.waitFor();
                Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.allapps.txt");
                p2.waitFor();
                Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.allapps.txt");
                p3.waitFor();
                lines = IOUtils.readLines(new FileInputStream(".allapps.txt"));
                values = new String[lines.size()];
                values = lines.toArray(values);
                moddedvalues = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    moddedvalues[i] = values[i].substring(8);
                }
                applist = new JList();
                applist.setModel(new AbstractListModel() {
                    public int getSize() {
                        return moddedvalues.length;
                    }

                    public Object getElementAt(int index) {
                        return moddedvalues[index];
                    }
                });
                scrollPane.setViewportView(applist);
                File file = new File(".allapps.txt");
                if (file.exists() && !file.isDirectory()) {
                    file.delete();
                }
            } catch (Exception e1) {
                System.err.println(e1);
            }
        }
    });
    btnRefresh.setBounds(125, 357, 220, 47);
    contentPane.add(btnRefresh);

    try {
        Process p1 = Runtime.getRuntime().exec("adb shell pm list packages > /sdcard/.allapps.txt");
        p1.waitFor();
        Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.allapps.txt");
        p2.waitFor();
        Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.allapps.txt");
        p3.waitFor();
        lines = IOUtils.readLines(new FileInputStream(".allapps.txt"));
        values = new String[lines.size()];
        values = lines.toArray(values);
        moddedvalues = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            moddedvalues[i] = values[i].substring(8);
        }
        applist = new JList();
        applist.setModel(new AbstractListModel() {
            public int getSize() {
                return moddedvalues.length;
            }

            public Object getElementAt(int index) {
                return moddedvalues[index];
            }
        });
        scrollPane.setViewportView(applist);
        File file = new File(".allapps.txt");
        if (file.exists() && !file.isDirectory()) {
            file.delete();
        }
    } catch (Exception e1) {
        System.err.println(e1);
    }
}