Example usage for javax.swing JList setSelectionMode

List of usage examples for javax.swing JList setSelectionMode

Introduction

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

Prototype

@BeanProperty(bound = false, enumerationValues = { "ListSelectionModel.SINGLE_SELECTION",
        "ListSelectionModel.SINGLE_INTERVAL_SELECTION",
        "ListSelectionModel.MULTIPLE_INTERVAL_SELECTION" }, description = "The selection mode.")
public void setSelectionMode(int selectionMode) 

Source Link

Document

Sets the selection mode for the list.

Usage

From source file:net.sf.jabref.gui.openoffice.OOBibBase.java

public static XTextDocument selectComponent(List<XTextDocument> list)
        throws UnknownPropertyException, WrappedTargetException, IndexOutOfBoundsException {
    String[] values = new String[list.size()];
    int ii = 0;//ww  w.  ja va2  s .  c  o  m
    for (XTextDocument doc : list) {
        values[ii] = String.valueOf(OOUtil.getProperty(doc.getCurrentController().getFrame(), "Title"));
        ii++;
    }
    JList<String> sel = new JList<>(values);
    sel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sel.setSelectedIndex(0);
    int ans = JOptionPane.showConfirmDialog(null, new JScrollPane(sel), Localization.lang("Select document"),
            JOptionPane.OK_CANCEL_OPTION);
    if (ans == JOptionPane.OK_OPTION) {
        return list.get(sel.getSelectedIndex());
    } else {
        return null;
    }
}

From source file:net.sf.jabref.exporter.ExportToClipboardAction.java

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel == null) {
        return;/*from  www  .  j  a  v  a 2  s .  co  m*/
    }
    if (panel.getSelectedEntries().isEmpty()) {
        message = Localization.lang("This operation requires one or more entries to be selected.");
        getCallBack().update();
        return;
    }

    List<IExportFormat> exportFormats = new LinkedList<>(ExportFormats.getExportFormats().values());
    Collections.sort(exportFormats, (e1, e2) -> e1.getDisplayName().compareTo(e2.getDisplayName()));
    String[] exportFormatDisplayNames = new String[exportFormats.size()];
    for (int i = 0; i < exportFormats.size(); i++) {
        IExportFormat exportFormat = exportFormats.get(i);
        exportFormatDisplayNames[i] = exportFormat.getDisplayName();
    }

    JList<String> list = new JList<>(exportFormatDisplayNames);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {
                    Localization.lang("Export with selected format"), Localization.lang("Return to JabRef") },
            Localization.lang("Export with selected format"));
    if (answer == JOptionPane.NO_OPTION) {
        return;
    }

    IExportFormat format = exportFormats.get(list.getSelectedIndex());

    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory();

    File tmp = null;
    try {
        // To simplify the exporter API we simply do a normal export to a temporary
        // file, and read the contents afterwards:
        tmp = File.createTempFile("jabrefCb", ".tmp");
        tmp.deleteOnExit();
        List<BibEntry> entries = panel.getSelectedEntries();

        // Write to file:
        format.performExport(panel.getBibDatabaseContext(), tmp.getPath(), panel.getEncoding(), entries);
        // Read the file and put the contents on the clipboard:
        StringBuilder sb = new StringBuilder();
        try (Reader reader = new InputStreamReader(new FileInputStream(tmp), panel.getEncoding())) {
            int s;
            while ((s = reader.read()) != -1) {
                sb.append((char) s);
            }
        }
        ClipboardOwner owner = (clipboard, content) -> {
            // Do nothing
        };
        RtfSelection rs = new RtfSelection(sb.toString());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
        message = Localization.lang("Entries exported to clipboard") + ": " + entries.size();

    } catch (Exception e) {
        LOGGER.error("Error exporting to clipboard", e); //To change body of catch statement use File | Settings | File Templates.
        message = Localization.lang("Error exporting to clipboard");
    } finally {
        // Clean up:
        if ((tmp != null) && !tmp.delete()) {
            LOGGER.info("Cannot delete temporary clipboard file");
        }
    }
}

From source file:net.sf.jabref.gui.exporter.ExportToClipboardAction.java

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel == null) {
        return;/*from  ww w.  j  a  v  a  2s . c o  m*/
    }
    if (panel.getSelectedEntries().isEmpty()) {
        message = Localization.lang("This operation requires one or more entries to be selected.");
        getCallBack().update();
        return;
    }

    List<IExportFormat> exportFormats = new LinkedList<>(ExportFormats.getExportFormats().values());
    Collections.sort(exportFormats, (e1, e2) -> e1.getDisplayName().compareTo(e2.getDisplayName()));
    String[] exportFormatDisplayNames = new String[exportFormats.size()];
    for (int i = 0; i < exportFormats.size(); i++) {
        IExportFormat exportFormat = exportFormats.get(i);
        exportFormatDisplayNames[i] = exportFormat.getDisplayName();
    }

    JList<String> list = new JList<>(exportFormatDisplayNames);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {
                    Localization.lang("Export with selected format"), Localization.lang("Return to JabRef") },
            Localization.lang("Export with selected format"));
    if (answer == JOptionPane.NO_OPTION) {
        return;
    }

    IExportFormat format = exportFormats.get(list.getSelectedIndex());

    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory();

    File tmp = null;
    try {
        // To simplify the exporter API we simply do a normal export to a temporary
        // file, and read the contents afterwards:
        tmp = File.createTempFile("jabrefCb", ".tmp");
        tmp.deleteOnExit();
        List<BibEntry> entries = panel.getSelectedEntries();

        // Write to file:
        format.performExport(panel.getBibDatabaseContext(), tmp.getPath(),
                panel.getBibDatabaseContext().getMetaData().getEncoding(), entries);
        // Read the file and put the contents on the clipboard:
        StringBuilder sb = new StringBuilder();
        try (Reader reader = new InputStreamReader(new FileInputStream(tmp),
                panel.getBibDatabaseContext().getMetaData().getEncoding())) {
            int s;
            while ((s = reader.read()) != -1) {
                sb.append((char) s);
            }
        }
        ClipboardOwner owner = (clipboard, content) -> {
            // Do nothing
        };
        RtfSelection rs = new RtfSelection(sb.toString());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
        message = Localization.lang("Entries exported to clipboard") + ": " + entries.size();

    } catch (Exception e) {
        LOGGER.error("Error exporting to clipboard", e); //To change body of catch statement use File | Settings | File Templates.
        message = Localization.lang("Error exporting to clipboard");
    } finally {
        // Clean up:
        if ((tmp != null) && !tmp.delete()) {
            LOGGER.info("Cannot delete temporary clipboard file");
        }
    }
}

From source file:ExtendedDnDDemo.java

private JPanel createList() {
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("List 0");
    listModel.addElement("List 1");
    listModel.addElement("List 2");
    listModel.addElement("List 3");
    listModel.addElement("List 4");
    listModel.addElement("List 5");
    listModel.addElement("List 6");
    listModel.addElement("List 7");
    listModel.addElement("List 8");

    JList list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JScrollPane scrollPane = new JScrollPane(list);
    scrollPane.setPreferredSize(new Dimension(400, 100));

    list.setDragEnabled(true);//from w ww .  ja va 2 s.  c  o  m
    list.setTransferHandler(new ListTransferHandler());

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createTitledBorder("List"));
    return panel;
}

From source file:ListCutPaste.java

public ListCutPaste() {
    super(new BorderLayout());
    lh = new ListTransferHandler();

    JPanel panel = new JPanel(new GridLayout(1, 3));
    DefaultListModel list1Model = new DefaultListModel();
    list1Model.addElement("alpha");
    list1Model.addElement("beta");
    list1Model.addElement("gamma");
    list1Model.addElement("delta");
    list1Model.addElement("epsilon");
    list1Model.addElement("zeta");
    JList list1 = new JList(list1Model);
    list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane sp1 = new JScrollPane(list1);
    sp1.setPreferredSize(new Dimension(400, 100));
    list1.setDragEnabled(true);//from w ww.  j a  v  a 2  s  . c o  m
    list1.setTransferHandler(lh);
    list1.setDropMode(DropMode.ON_OR_INSERT);
    setMappings(list1);
    JPanel pan1 = new JPanel(new BorderLayout());
    pan1.add(sp1, BorderLayout.CENTER);
    pan1.setBorder(BorderFactory.createTitledBorder("Greek Alphabet"));
    panel.add(pan1);

    DefaultListModel list2Model = new DefaultListModel();
    list2Model.addElement("uma");
    list2Model.addElement("dois");
    list2Model.addElement("tres");
    list2Model.addElement("quatro");
    list2Model.addElement("cinco");
    list2Model.addElement("seis");
    JList list2 = new JList(list2Model);
    list2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list2.setDragEnabled(true);
    JScrollPane sp2 = new JScrollPane(list2);
    sp2.setPreferredSize(new Dimension(400, 100));
    list2.setTransferHandler(lh);
    list2.setDropMode(DropMode.INSERT);
    setMappings(list2);
    JPanel pan2 = new JPanel(new BorderLayout());
    pan2.add(sp2, BorderLayout.CENTER);
    pan2.setBorder(BorderFactory.createTitledBorder("Portuguese Numbers"));
    panel.add(pan2);

    DefaultListModel list3Model = new DefaultListModel();
    list3Model.addElement("adeen");
    list3Model.addElement("dva");
    list3Model.addElement("tri");
    list3Model.addElement("chyetirye");
    list3Model.addElement("pyat");
    list3Model.addElement("shest");
    JList list3 = new JList(list3Model);
    list3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list3.setDragEnabled(true);
    JScrollPane sp3 = new JScrollPane(list3);
    sp3.setPreferredSize(new Dimension(400, 100));
    list3.setTransferHandler(lh);
    list3.setDropMode(DropMode.ON);
    setMappings(list3);
    JPanel pan3 = new JPanel(new BorderLayout());
    pan3.add(sp3, BorderLayout.CENTER);
    pan3.setBorder(BorderFactory.createTitledBorder("Russian Numbers"));
    panel.add(pan3);

    setPreferredSize(new Dimension(500, 200));
    add(panel, BorderLayout.CENTER);
}

From source file:com.t3.client.ui.AddResourceDialog.java

public void initLibraryList() {
    JList list = getLibraryList();
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    list.setModel(new MessageListModel(I18N.getText("dialog.addresource.downloading")));
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;/*  ww  w.j  av  a2s.c o  m*/
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

From source file:net.sf.jabref.gui.preftabs.PreferencesDialog.java

public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;/*from ww w. j  a v a2  s.com*/

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        String o = chooser.getSelectedValue();
        cardLayout.show(main, o);
    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.SAVE_DIALOG, false);
        if (filename == null) {
            return;
        }
        File file = new File(filename);
        if (!file.exists() || (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("'%0' exists. Overwrite file?", file.getName()),
                Localization.lang("Export preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {

            try {
                prefs.exportPreferences(filename);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.OPEN_DIALOG, false);
        if (filename != null) {
            try {
                prefs.importPreferences(filename);
                updateAfterPreferenceChanges();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    showPreferences.addActionListener(
            e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                    .setVisible(true));
    resetPreferences.addActionListener(e -> {
        if (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("Are you sure you want to reset all settings to default values?"),
                Localization.lang("Reset preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            try {
                prefs.clear();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Reset preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Reset preferences"), JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
        }
    });

    setValues();

    pack();

}

From source file:DragListDemo.java

public DragListDemo() {
    arrayListHandler = new ArrayListTransferHandler();
    JList list1, list2;

    DefaultListModel list1Model = new DefaultListModel();
    list1Model.addElement("0 (list 1)");
    list1Model.addElement("1 (list 1)");
    list1Model.addElement("2 (list 1)");
    list1Model.addElement("3 (list 1)");
    list1Model.addElement("4 (list 1)");
    list1Model.addElement("5 (list 1)");
    list1Model.addElement("6 (list 1)");
    list1 = new JList(list1Model);
    list1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list1.setTransferHandler(arrayListHandler);
    list1.setDragEnabled(true);//from  w w w. j  av a 2  s.com
    JScrollPane list1View = new JScrollPane(list1);
    list1View.setPreferredSize(new Dimension(200, 100));
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BorderLayout());
    panel1.add(list1View, BorderLayout.CENTER);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    DefaultListModel list2Model = new DefaultListModel();
    list2Model.addElement("0 (list 2)");
    list2Model.addElement("1 (list 2)");
    list2Model.addElement("2 (list 2)");
    list2Model.addElement("3 (list 2)");
    list2Model.addElement("4 (list 2)");
    list2Model.addElement("5 (list 2)");
    list2Model.addElement("6 (list 2)");
    list2 = new JList(list2Model);
    list2.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list2.setTransferHandler(arrayListHandler);
    list2.setDragEnabled(true);
    JScrollPane list2View = new JScrollPane(list2);
    list2View.setPreferredSize(new Dimension(200, 100));
    JPanel panel2 = new JPanel();
    panel2.setLayout(new BorderLayout());
    panel2.add(list2View, BorderLayout.CENTER);
    panel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    setLayout(new BorderLayout());
    add(panel1, BorderLayout.LINE_START);
    add(panel2, BorderLayout.LINE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:org.gumtree.vis.hist2d.Hist2DChartEditor.java

private JPanel createHelpPanel(JFreeChart chart) {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = new Hist2DHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);/*from   w  w  w. j av  a2s . c o  m*/
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;

}