Example usage for javax.swing AbstractListModel AbstractListModel

List of usage examples for javax.swing AbstractListModel AbstractListModel

Introduction

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

Prototype

AbstractListModel

Source Link

Usage

From source file:Main.java

public static ListModel toListModel(final List elements) {
    return (new AbstractListModel() {
        public int getSize() {
            return (elements.size());
        }/*from  ww w.  j a  v a  2s  .  c  o m*/

        public Object getElementAt(int index) {
            return (elements.get(index));
        }
    });
}

From source file:Main.java

public Main() {
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    jList1.setModel(new AbstractListModel() {
        String[] strings = { "Computer", "Mouse", "HDD" };

        public int getSize() {
            return strings.length;
        }/*from  www  . j ava2 s.com*/

        public Object getElementAt(int i) {
            return strings[i];
        }
    });
    jList1.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            jList1ValueChanged(evt);
        }
    });
    jTextField2.setText("jTextField1");
    jPanel1.add(new JScrollPane(jList1));
    jPanel1.add(jTextField2);
    frame.add(jPanel1);
    frame.pack();
    frame.setVisible(true);
}

From source file:org.signserver.admin.gui.ViewCertificateFrame.java

public ViewCertificateFrame(final List<X509Certificate> certificates) {
    this.certificates = certificates;
    this.certificate = certificates.get(0);
    initComponents();//from w w  w. ja  v  a 2  s.  co  m
    chainList.setModel(new AbstractListModel() {

        @Override
        public int getSize() {
            return certificates.size();
        }

        @Override
        public Object getElementAt(int index) {
            return certificates.get(index);
        }
    });
    chainList.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(final JList list, Object value, final int index,
                final boolean isSelected, final boolean cellHasFocus) {
            if (value instanceof X509Certificate) {
                final X509Certificate cert = (X509Certificate) value;
                value = cert.getSubjectDN().getName();
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }

    });
    chainList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                viewCertificate((X509Certificate) chainList.getSelectedValue());
            }
        }
    });

    fieldsList.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(final JList list, Object value, final int index,
                final boolean isSelected, final boolean cellHasFocus) {
            if (value instanceof Field) {
                value = ((Field) value).getName();
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }

    });
    fieldsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                viewFieldValue((Field) fieldsList.getSelectedValue());
            }
        }
    });

    subjectTextArea.setText(certificate.getSubjectDN().getName());
    issuerTextArea.setText(certificate.getIssuerDN().getName());
    serialNumberField.setText(certificate.getSerialNumber().toString(16));
    notBeforeLabel.setText(String.valueOf(certificate.getNotBefore()));
    notAfterLabel.setText(String.valueOf(certificate.getNotAfter()));

    String fingerprint = "";
    try {
        fingerprint = calcFingerprint(certificate.getEncoded());
    } catch (CertificateEncodingException ex) {
        LOG.error("Error calculating certificate fingerprint", ex);
    }
    fingerprintLabel.setText(fingerprint);

    usages = new ArrayList<String>();
    boolean[] keyUsages = certificate.getKeyUsage();
    if (keyUsages != null) {
        // digitalSignature        (0),
        if (keyUsages[0]) {
            usages.add("digitalSignature");
        }
        // nonRepudiation          (1),
        if (keyUsages[1]) {
            usages.add("nonRepudiation");
        }
        // keyEncipherment         (2),
        if (keyUsages[2]) {
            usages.add("keyEncipherment");
        }
        // dataEncipherment        (3),
        if (keyUsages[3]) {
            usages.add("dataEncipherment");
        }
        // keyAgreement            (4),
        if (keyUsages[4]) {
            usages.add("keyAgreement");
        }
        // keyCertSign             (5),
        if (keyUsages[5]) {
            usages.add("keyCertSign");
        }
        // cRLSign                 (6),
        if (keyUsages[6]) {
            usages.add("cRLSign");
        }
        // encipherOnly            (7),
        if (keyUsages[7]) {
            usages.add("encipherOnly");
        }
        // decipherOnly
        if (keyUsages[8]) {
            usages.add("decipherOnly");
        }
    }

    try {
        final List<String> eku = certificate.getExtendedKeyUsage();
        if (eku != null) {
            usages.addAll(eku);
        }
    } catch (CertificateParsingException ex) {
        LOG.error("Error getting extended key usage", ex);
    }

    usagesList.setModel(new AbstractListModel() {

        @Override
        public int getSize() {
            return usages.size();
        }

        @Override
        public Object getElementAt(int index) {
            return usages.get(index);
        }
    });

    chainList.setSelectedIndex(0);
}

From source file:edu.ku.brc.specify.tasks.subpane.PickListProcessor.java

public void setViewable(final FormPane formPane) {
    this.formPane = formPane;

    if (formPane != null) {
        viewable = formPane.getViewable();
        pickList = (PickList) viewable.getDataObj();

        name = viewable.getCompById("name");
        list = viewable.getCompById("items");
        title = viewable.getCompById("title");
        value = viewable.getCompById("value");

        list.setModel(new AbstractListModel() {
            public int getSize() {
                return usedInList.size();
            }/* ww w.  j a  v  a 2s .  c o  m*/

            public Object getElementAt(int index) {
                return usedInList.get(index);
            }
        });

        JButton saveBtn = viewable.getCompById("savePL");
        viewable.getValidator().addEnableItem(saveBtn, FormValidator.EnableType.ValidAndChangedItems);

        //Viewable.getValidator().addRuleObjectMapping("titleVal", new TitleValidator(name, titlesList));
        viewable.getValidator().addRuleObjectMapping("processor", this);

        addBtn = viewable.getCompById("AddItem");
        removeBtn = viewable.getCompById("RemoveItem");

        addBtn.addActionListener(new ActionListener() {
            @SuppressWarnings("unchecked")
            public void actionPerformed(ActionEvent ae) {
                PickListItem pli = new PickListItem(title.getText(), null,
                        new Timestamp(System.currentTimeMillis()));
                pickList.addItem(pli);
                pli.setPickList(pickList);
                title.setText("");
                value.setText("");

                ListModel lm = list.getModel();
                if (lm instanceof DefaultListModel) {
                    ((DefaultListModel) lm).addElement(pli);
                } else {
                    throw new RuntimeException("Unknown model type for JList[" + lm + "]");
                }
                list.setSelectedIndex(-1);
                viewable.getValidator().validateForm();
            }
        });

        removeBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                Object[] objs = list.getSelectedValues();
                for (Object o : objs) {
                    pickList.removeItem((PickListItemIFace) o);
                    ListModel lm = list.getModel();
                    if (lm instanceof DefaultListModel) {
                        ((DefaultListModel) lm).removeElement(o);
                    } else {
                        throw new RuntimeException("Unknown model type for JList[" + lm + "]");
                    }
                }
                list.setSelectedIndex(-1);
                viewable.getValidator().validateForm();
            }
        });

        JButton deleteBtn = viewable.getCompById("deletePL");
        deleteBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                CommandDispatcher.dispatch(new CommandAction(SystemSetupTask.SYSTEMSETUPTASK, "DeletePickList",
                        viewable.getDataObj()));

            }
        });

        saveBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                pickList.setName(((JTextField) viewable.getCompById("name")).getText());

                String sizeStr = ((JTextField) viewable.getCompById("sizeLimit")).getText().trim();
                pickList.setSizeLimit(isNotEmpty(sizeStr) ? Integer.parseInt(sizeStr) : 0);

                pickList.setReadOnly(((JCheckBox) viewable.getCompById("readOnly")).isSelected());

                CommandDispatcher.dispatch(new CommandAction(SystemSetupTask.SYSTEMSETUPTASK, "SavePickList",
                        viewable.getDataObj()));

            }
        });

        viewable.getValidator().validateForm();

    } else {
        // do cleanup
        viewable = null;
        pickList = null;
    }
}

From source file:dpcs.AppPackagesList.java

@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public AppPackagesList() {
    setResizable(false);//  w  w w  . j a va  2  s. c om
    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);
    }
}

From source file:op.tools.DlgListSelector.java

/**
 * This method is called from within the constructor to
 * initialize the form.//from  w w w .  ja va  2 s .c  o  m
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the PrinterForm Editor.
 */
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
    lblTopic = new JLabel();
    lblDetail = new JLabel();
    jScrollPane1 = new JScrollPane();
    lstSelect = new JList();
    panel1 = new JPanel();
    btnApply = new JButton();
    btnCancel = new JButton();

    //======== this ========
    setResizable(false);
    setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout("$rgap, $lcgap, default:grow, $lcgap, $rgap",
            "$rgap, 2*($lgap, fill:default), $lgap, fill:default:grow, $lgap, fill:default, $lgap, $rgap"));

    //---- lblTopic ----
    lblTopic.setFont(new Font("Dialog", Font.BOLD, 14));
    lblTopic.setText("jLabel1");
    contentPane.add(lblTopic, CC.xywh(3, 3, 2, 1));

    //---- lblDetail ----
    lblDetail.setFont(new Font("Dialog", Font.PLAIN, 12));
    lblDetail.setText("jLabel2");
    contentPane.add(lblDetail, CC.xywh(3, 5, 2, 1));

    //======== jScrollPane1 ========
    {

        //---- lstSelect ----
        lstSelect.setModel(new AbstractListModel() {
            String[] values = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

            @Override
            public int getSize() {
                return values.length;
            }

            @Override
            public Object getElementAt(int i) {
                return values[i];
            }
        });
        lstSelect.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                lstSelectMouseClicked(e);
            }
        });
        jScrollPane1.setViewportView(lstSelect);
    }
    contentPane.add(jScrollPane1, CC.xywh(3, 7, 2, 1));

    //======== panel1 ========
    {
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.LINE_AXIS));

        //---- btnApply ----
        btnApply.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png")));
        btnApply.setText("W\u00e4hlen");
        btnApply.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnApplyActionPerformed(e);
            }
        });
        panel1.add(btnApply);

        //---- btnCancel ----
        btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png")));
        btnCancel.setText("Abbrechen");
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnCancelActionPerformed(e);
            }
        });
        panel1.add(btnCancel);
    }
    contentPane.add(panel1, CC.xy(3, 9, CC.RIGHT, CC.DEFAULT));
    setSize(600, 441);
    setLocationRelativeTo(null);
}

From source file:com.anrisoftware.prefdialog.fields.buttongroup.ButtonGroupField.java

private AbstractListModel<Action> createModel(final List<Action> actions) {
    return new AbstractListModel<Action>() {

        @Override/*ww w .  j a v a2s .c  om*/
        public int getSize() {
            return actions.size();
        }

        @Override
        public Action getElementAt(int i) {
            return actions.get(i);
        }
    };
}

From source file:dpcs.UninstallSystemApps.java

@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public UninstallSystemApps() {
    setResizable(false);/*from   w w  w  . j  a va 2  s . co  m*/
    setTitle("Uninstall System Apps");
    setIconImage(
            Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png")));
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 482, 475);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel AppStatus = new JLabel("");
    AppStatus.setBounds(12, 393, 456, 17);
    contentPane.add(AppStatus);

    SystemAppUninstallDone = new JLabel("");
    SystemAppUninstallDone.setBounds(151, 312, 186, 56);
    contentPane.add(SystemAppUninstallDone);

    JLabel lblSelect = new JLabel("Select an app to remove");
    lblSelect.setBounds(26, 12, 405, 17);
    contentPane.add(lblSelect);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(22, 41, 428, 259);
    contentPane.add(scrollPane);

    final JButton btnUninstall = new JButton("Uninstall");
    btnUninstall.setToolTipText("Uninstall the selected app");
    btnUninstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SystemAppUninstallDone.setText("");
            if (list.getSelectedValue() == null) {
                JOptionPane.showMessageDialog(null, "Please select an app first");
            } else {
                try {
                    AppStatus.setText("Uninstalling...");
                    Process p1 = Runtime.getRuntime().exec("adb remount");
                    p1.waitFor();
                    String[] commands = new String[3];
                    commands[0] = "adb shell su -c rm -r ";
                    commands[1] = "/system/app/";
                    commands[2] = " " + list.getSelectedValue();
                    Process p2 = Runtime.getRuntime().exec(commands, null);
                    p2.waitFor();
                    Process p3 = Runtime.getRuntime()
                            .exec("adb shell ls /system/app/ > /sdcard/.systemapps.txt");
                    p3.waitFor();
                    Process p4 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt");
                    p4.waitFor();
                    Process p5 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt");
                    p5.waitFor();
                    lines = IOUtils.readLines(new FileInputStream(".systemapps.txt"));
                    values = new String[lines.size()];
                    values = lines.toArray(values);
                    list = new JList();
                    list.setModel(new AbstractListModel() {
                        public int getSize() {
                            return values.length;
                        }

                        public Object getElementAt(int index) {
                            return values[index];
                        }
                    });
                    scrollPane.setViewportView(list);
                    File file = new File(".systemapps.txt");
                    if (file.exists() && !file.isDirectory()) {
                        file.delete();
                    }
                    AppStatus.setText("App has been uninstalled successfully");
                    SystemAppUninstallDone
                            .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png")));
                    btnUninstall.setSelected(false);
                } catch (Exception e1) {
                    System.err.println(e1);
                }
            }
        }
    });
    btnUninstall.setBounds(26, 327, 107, 27);
    contentPane.add(btnUninstall);

    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 ls /system/app/ > /sdcard/.systemapps.txt");
                p1.waitFor();
                Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt");
                p2.waitFor();
                Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt");
                p3.waitFor();
                lines = IOUtils.readLines(new FileInputStream(".systemapps.txt"));
                values = new String[lines.size()];
                values = lines.toArray(values);
                list = new JList();
                list.setModel(new AbstractListModel() {
                    public int getSize() {
                        return values.length;
                    }

                    public Object getElementAt(int index) {
                        return values[index];
                    }
                });
                scrollPane.setViewportView(list);
                File file = new File(".systemapps.txt");
                if (file.exists() && !file.isDirectory()) {
                    file.delete();
                }
            } catch (Exception e1) {
                System.err.println(e1);
            }
        }
    });
    btnRefresh.setBounds(344, 327, 107, 27);
    contentPane.add(btnRefresh);

    try {
        Process p1 = Runtime.getRuntime().exec("adb shell ls /system/app/ > /sdcard/.systemapps.txt");
        p1.waitFor();
        Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt");
        p2.waitFor();
        Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt");
        p3.waitFor();
        lines = IOUtils.readLines(new FileInputStream(".systemapps.txt"));
        values = new String[lines.size()];
        values = lines.toArray(values);
        list = new JList();
        list.setModel(new AbstractListModel() {
            public int getSize() {
                return values.length;
            }

            public Object getElementAt(int index) {
                return values[index];
            }
        });
        scrollPane.setViewportView(list);
        JLabel lblNewLabel = new JLabel("Note: You should also remove app's odex file if it exists");
        lblNewLabel.setBounds(25, 374, 438, 17);
        contentPane.add(lblNewLabel);

        JLabel label = new JLabel("Needs root and does not work on production android builds!");
        label.setBounds(25, 413, 454, 17);
        contentPane.add(label);
        File file = new File(".systemapps.txt");
        if (file.exists() && !file.isDirectory()) {
            file.delete();
        }
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:dpcs.UninstallPrivApps.java

@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public UninstallPrivApps() {
    setResizable(false);//from  w ww .j a va  2  s .  c o  m
    setTitle("Uninstall Priv-apps");
    setIconImage(
            Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png")));
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 482, 500);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel AppStatus = new JLabel("");
    AppStatus.setBounds(8, 404, 456, 17);
    contentPane.add(AppStatus);

    PrivAppUninstallDone = new JLabel("");
    PrivAppUninstallDone.setText("");
    PrivAppUninstallDone.setBounds(151, 312, 186, 56);
    contentPane.add(PrivAppUninstallDone);

    JLabel lblSelect = new JLabel("Select an app to remove");
    lblSelect.setBounds(25, 12, 405, 17);
    contentPane.add(lblSelect);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(22, 41, 428, 259);
    contentPane.add(scrollPane);

    final JButton btnUninstall = new JButton("Uninstall");
    btnUninstall.setToolTipText("Uninstall the selected app");
    btnUninstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PrivAppUninstallDone.setText("");
            if (list.getSelectedValue() == null) {
                JOptionPane.showMessageDialog(null, "Please select an app first");
            } else {
                try {
                    AppStatus.setText("Uninstalling...");
                    Process p1 = Runtime.getRuntime().exec("adb remount");
                    p1.waitFor();
                    String[] commands = new String[3];
                    commands[0] = "adb shell su -c rm -r";
                    commands[1] = "/system/priv-app/";
                    commands[2] = " " + list.getSelectedValue();
                    Process p2 = Runtime.getRuntime().exec(commands, null);
                    p2.waitFor();
                    Process p3 = Runtime.getRuntime()
                            .exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt");
                    p3.waitFor();
                    Process p4 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt");
                    p4.waitFor();
                    Process p5 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt");
                    p5.waitFor();
                    lines = IOUtils.readLines(new FileInputStream(".privapps.txt"));
                    values = new String[lines.size()];
                    values = lines.toArray(values);
                    list = new JList();
                    list.setModel(new AbstractListModel() {
                        public int getSize() {
                            return values.length;
                        }

                        public Object getElementAt(int index) {
                            return values[index];
                        }
                    });
                    scrollPane.setViewportView(list);

                    File file = new File(".privapps.txt");
                    if (file.exists() && !file.isDirectory()) {
                        file.delete();
                    }
                    AppStatus.setText("App has been uninstalled successfully");
                    PrivAppUninstallDone
                            .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png")));
                    btnUninstall.setSelected(false);
                } catch (Exception e1) {
                    System.err.println(e1);
                }
            }
        }
    });
    btnUninstall.setBounds(26, 327, 107, 27);
    contentPane.add(btnUninstall);

    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 ls /system/priv-app/ > /sdcard/.privapps.txt");
                p1.waitFor();
                Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt");
                p2.waitFor();
                Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt");
                p3.waitFor();
                lines = IOUtils.readLines(new FileInputStream(".privapps.txt"));
                values = new String[lines.size()];
                values = lines.toArray(values);
                list = new JList();
                list.setModel(new AbstractListModel() {
                    public int getSize() {
                        return values.length;
                    }

                    public Object getElementAt(int index) {
                        return values[index];
                    }
                });
                scrollPane.setViewportView(list);
                File file = new File(".privapps.txt");
                if (file.exists() && !file.isDirectory()) {
                    file.delete();
                }
            } catch (Exception e1) {
                System.err.println(e1);
            }
        }
    });
    btnRefresh.setBounds(344, 327, 107, 27);
    contentPane.add(btnRefresh);

    try {
        Process p1 = Runtime.getRuntime().exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt");
        p1.waitFor();
        Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt");
        p2.waitFor();
        Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt");
        p3.waitFor();
        lines = IOUtils.readLines(new FileInputStream(".privapps.txt"));
        values = new String[lines.size()];
        values = lines.toArray(values);
        list = new JList();
        list.setModel(new AbstractListModel() {
            public int getSize() {
                return values.length;
            }

            public Object getElementAt(int index) {
                return values[index];
            }
        });
        scrollPane.setViewportView(list);

        JLabel lblNewLabel = new JLabel("Note: You should also remove app's odex file if it exits ");
        lblNewLabel.setBounds(25, 374, 438, 17);
        contentPane.add(lblNewLabel);

        JLabel lblNeedsRootAnd = new JLabel("Needs root and does not work on production android builds!");
        lblNeedsRootAnd.setBounds(25, 426, 454, 17);
        contentPane.add(lblNeedsRootAnd);

        JLabel lblOnlyForAndroid = new JLabel("Uninstallation only for android 4.4.x and higher!");
        lblOnlyForAndroid.setBounds(8, 452, 450, 15);
        contentPane.add(lblOnlyForAndroid);
        File file = new File(".privapps.txt");
        if (file.exists() && !file.isDirectory()) {
            file.delete();
        }
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:dpcs.UninstallUserApps.java

@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public UninstallUserApps() {
    setResizable(false);//from  www.jav  a 2 s. c  om
    setTitle("Uninstall User Apps");
    setIconImage(
            Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png")));
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 482, 430);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel AppStatus = new JLabel("");
    AppStatus.setBounds(12, 366, 456, 17);
    contentPane.add(AppStatus);

    UserAppUninstallDone = new JLabel("");
    UserAppUninstallDone.setText("");
    UserAppUninstallDone.setBounds(151, 312, 186, 56);
    contentPane.add(UserAppUninstallDone);

    JLabel lblSelect = new JLabel("Select an app to remove");
    lblSelect.setBounds(26, 12, 405, 17);
    contentPane.add(lblSelect);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(22, 41, 428, 259);
    contentPane.add(scrollPane);

    final JButton btnUninstall = new JButton("Uninstall");
    btnUninstall.setToolTipText("Uninstall the selected app");
    btnUninstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UserAppUninstallDone.setText("");
            if (list.getSelectedValue() == null) {
                JOptionPane.showMessageDialog(null, "Please select an app first");
            } else {
                try {
                    AppStatus.setText("Uninstalling...");
                    String[] commands = new String[3];
                    commands[0] = "adb";
                    commands[1] = "uninstall";
                    commands[2] = "" + list.getSelectedValue();
                    Process p1 = Runtime.getRuntime().exec(commands, null);
                    p1.waitFor();
                    Process p2 = Runtime.getRuntime()
                            .exec("adb shell pm list packages -3 > /sdcard/.userapps.txt");
                    p2.waitFor();
                    Process p3 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt");
                    p3.waitFor();
                    Process p4 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt");
                    p4.waitFor();
                    lines = IOUtils.readLines(new FileInputStream(".userapps.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);
                    }
                    list = new JList();
                    list.setModel(new AbstractListModel() {
                        public int getSize() {
                            return moddedvalues.length;
                        }

                        public Object getElementAt(int index) {
                            return moddedvalues[index];
                        }
                    });
                    scrollPane.setViewportView(list);
                    File file = new File(".userapps.txt");
                    if (file.exists() && !file.isDirectory()) {
                        file.delete();
                    }
                    AppStatus.setText("App has been uninstalled successfully");
                    UserAppUninstallDone
                            .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png")));
                    btnUninstall.setSelected(false);
                } catch (Exception e1) {
                    System.err.println(e1);
                }
            }
        }
    });
    btnUninstall.setBounds(26, 327, 107, 27);
    contentPane.add(btnUninstall);

    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 -3 > /sdcard/.userapps.txt");
                p1.waitFor();
                Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt");
                p2.waitFor();
                Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt");
                p3.waitFor();
                lines = IOUtils.readLines(new FileInputStream(".userapps.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);
                }
                list = new JList();
                list.setModel(new AbstractListModel() {
                    public int getSize() {
                        return moddedvalues.length;
                    }

                    public Object getElementAt(int index) {
                        return moddedvalues[index];
                    }
                });
                scrollPane.setViewportView(list);
                File file = new File(".userapps.txt");
                if (file.exists() && !file.isDirectory()) {
                    file.delete();
                }
            } catch (Exception e1) {
                System.err.println(e1);
            }
        }
    });
    btnRefresh.setBounds(344, 327, 107, 27);
    contentPane.add(btnRefresh);

    try {
        Process p1 = Runtime.getRuntime().exec("adb shell pm list packages -3 > /sdcard/.userapps.txt");
        p1.waitFor();
        Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt");
        p2.waitFor();
        Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt");
        p3.waitFor();
        lines = IOUtils.readLines(new FileInputStream(".userapps.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);
        }
        list = new JList();
        list.setModel(new AbstractListModel() {
            public int getSize() {
                return moddedvalues.length;
            }

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