Example usage for javax.swing JList setCellRenderer

List of usage examples for javax.swing JList setCellRenderer

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "The component used to draw the cells.")
public void setCellRenderer(ListCellRenderer<? super E> cellRenderer) 

Source Link

Document

Sets the delegate that is used to paint each cell in the list.

Usage

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java

/**
 * Export data //from  ww w  . j a  v a2  s. c o  m
 */
protected void exportSingleLocale() {
    statusBar.setText(getResourceString("SchemaLocalizerFrame.EXPORTING")); //$NON-NLS-1$
    statusBar.paintImmediately(statusBar.getBounds());

    schemaLocPanel.getAllDataFromUI();

    if (localizableIO.hasChanged()) {
        if (UIRegistry.askYesNoLocalized("SAVE", "CANCEL",
                UIRegistry.getResourceString("SchemaLocalizerFrame.NEEDS_SAVING"),
                "SAVE") == JOptionPane.YES_NO_OPTION) {
            localizableIO.save();
        } else {
            return;
        }
    }

    Vector<Locale> stdLocales = SchemaI18NService.getInstance().getStdLocaleList(false);
    final JList list = new JList(stdLocales);
    list.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                setText(((Locale) value).getDisplayName());
            }
            return this;
        }
    });

    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));
    pb.add(UIHelper.createScrollPane(list), (new CellConstraints()).xy(1, 1));
    pb.setDefaultDialogBorder();

    final CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(),
            getResourceString("SchemaLocalizerFrame.CHOOSE_LOCALE"), true, pb.getPanel());
    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                dlg.getOkBtn().setEnabled(list.getSelectedValue() != null);
            }
        }
    });
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    UIHelper.centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        Locale locale = (Locale) list.getSelectedValue();
        if (locale != null) {
            FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(),
                    getResourceString("SchemaLocalizerFrame.SVFILENAME"), FileDialog.SAVE);
            fileDlg.setVisible(true);
            String fileName = fileDlg.getFile();
            if (StringUtils.isNotEmpty(fileName)) {
                File outFile = new File(fileDlg.getDirectory() + File.separator + fileName);
                boolean savedOK = localizableIO.exportSingleLanguageToDirectory(outFile, locale);
                if (savedOK) {
                    String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTEDTO",
                            locale.getDisplayName(), outFile.getAbsolutePath());
                    UIRegistry.displayInfoMsgDlg(msg);
                } else {
                    String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTING_ERR",
                            outFile.getAbsolutePath());
                    UIRegistry.showError(msg);
                }

            }
        }
    }
}

From source file:com.raddle.tools.MergeMain.java

private void setCellRenderer(JList list) {
    list.setCellRenderer(new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override//from   ww  w  . j a  va  2  s  . c o m
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                PropertyLine line = (PropertyLine) value;
                boolean isInSelected = false;
                for (int selectedIndex : list.getSelectedIndices()) {
                    if (index == selectedIndex) {
                        isInSelected = true;
                    }
                }
                if (!isInSelected) {
                    if (CompareResult.extra == line.getCompareResult()) {
                        c.setBackground(new Color(0xFFC48E));
                    } else if (CompareResult.different == line.getCompareResult()) {
                        c.setBackground(new Color(0xBBBBFF));
                    }
                }
                if (line.getState() != null) {
                    if (LineState.added == line.getState()) {
                        c.setForeground(new Color(0xCC0033));
                    } else if (LineState.updated == line.getState()) {
                        c.setForeground(new Color(0x0066CC));
                    } else if (LineState.deleted == line.getState()) {
                        if (line.getOriginalValue() == null) {
                            c.setForeground(new Color(0xAAAAAA));
                        } else {
                            c.setForeground(new Color(0x666666));
                        }
                        Map<Attribute, Object> map = new HashMap<Attribute, Object>();
                        map.put(TextAttribute.FONT, c.getFont());
                        map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
                        c.setFont(Font.getFont(map));
                    }
                }
            }
            return c;
        }

    });
}

From source file:fr.free.hd.servers.gui.PhonemView.java

@Override
protected JComponent createControl() {
    final JPanel view = new JPanel(new BorderLayout());

    Collection<Phonem> phonesList = phonemsDAO.getPhonems();
    Map<String, Phonem> mapList = new HashMap<String, Phonem>();
    for (Phonem phonem : phonesList) {
        mapList.put(phonem.getPhonem(), phonem);
    }/*from ww  w .  j  a va  2  s  .c  om*/

    final StatementListModel model = new StatementListModel(mapList);

    printCommand.setModel(model);
    printCommand.setFace(face);
    copyCommand.setModel(model);
    copyCommand.setFace(face);

    list = new JList(model);
    final JScrollPane sp = new JScrollPane(list);
    final JTextField field = new JTextField();
    field.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

    });

    final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList);
    final JList phonemList = new JList(phonemModel);
    final JScrollPane spPhonemList = new JScrollPane(phonemList);
    phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        // private int oldIndex = -1;
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex());
                field.setText(field.getText() + innerPhonem.getPhonem());
            }
        }
    });
    phonemList.setCellRenderer(new PhonemListRenderer());
    list.setCellRenderer(new StatementPhonemListRenderer(face));
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(1);

    view.add(spPhonemList, BorderLayout.WEST);
    view.add(sp, BorderLayout.CENTER);
    view.add(field, BorderLayout.SOUTH);

    field.requestFocus();

    return view;
}

From source file:com.projity.pm.graphic.chart.ChartLegend.java

JList getListInstance(boolean cost) {
    final JList list = new JList() { // do not want to update the UI. see below also
        private static final long serialVersionUID = 1L;

        public void updateUI() {
            if (!Environment.isNewLook())
                super.updateUI();
        }//from  w  w w .j a va  2  s .c o m
    };
    if (Environment.isNewLook()) // The PLAF can override the custom renderer. This avoids that
        list.setUI(new BasicListUI());
    list.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setCellRenderer(new ListRenderer());
    setListFields(list, cost);
    if (!simple) {
        list.setSelectedIndex(0); // start off with first choice selected         
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (chartInfo.isRestoring()) // don't want to listen if updating from workspace
                    return;
                if (e.getValueIsAdjusting() == false) {
                    chartInfo.setTraces(list.getSelectedValues());
                }
            }
        });
    }

    return list;
}

From source file:com.rapidminer.gui.properties.RegexpPropertyDialog.java

public RegexpPropertyDialog(final Collection<String> items, String predefinedRegexp, String description) {
    super(ApplicationFrame.getApplicationFrame(), "parameter.regexp", ModalityType.APPLICATION_MODAL,
            new Object[] {});
    this.items = items;
    this.supportsItems = items != null;
    this.infoText = "<html>" + I18N.getMessage(I18N.getGUIBundle(), getKey() + ".title") + ": <br/>"
            + description + "</html>";
    Dimension size = new Dimension(420, 500);
    this.setMinimumSize(size);
    this.setPreferredSize(size);

    JPanel panel = new JPanel(createGridLayout(1, supportsItems ? 2 : 1));

    // create regexp text field
    regexpTextField = new JTextField(predefinedRegexp);
    regexpTextField.setToolTipText(//from   ww  w . jav  a 2 s . co  m
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.tip"));
    regexpTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            fireRegularExpressionUpdated();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });
    regexpTextField.requestFocus();

    // create replacement text field
    replacementTextField = new JTextField();
    replacementTextField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.tip"));
    replacementTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            fireRegularExpressionUpdated();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });

    // create inline search documents
    inlineSearchDocument = new RegexpSearchStyledDocument();
    inlineReplaceDocument = new RegexpReplaceStyledDocument();

    // create search results list
    DefaultListCellRenderer resultCellRenderer = new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setBackground(list.getBackground());
            setForeground(list.getForeground());
            setBorder(getNoFocusBorder());
            return this;
        }

        private Border getNoFocusBorder() {
            Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray);
            return border;
        }
    };

    JList<RegExpResult> regexpFindingsList = new JList<RegExpResult>(resultsListModel);
    regexpFindingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    regexpFindingsList.setLayoutOrientation(JList.VERTICAL);
    regexpFindingsList.setCellRenderer(resultCellRenderer);

    // regexp panel on left side of dialog
    JPanel regexpPanel = new JPanel(new GridBagLayout());
    regexpPanel.setBorder(createTitledBorder(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.border")));
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(4, 4, 4, 0);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    regexpPanel.add(regexpTextField, c);

    // make shortcut button
    final Action nullAction = new DefaultAction();
    PlainArrowDropDownButton autoWireDropDownButton = PlainArrowDropDownButton.makeDropDownButton(nullAction);

    for (String[] popupItem : (String[][]) ArrayUtils.addAll(regexpConstructs, regexpShortcuts)) {
        String shortcut = popupItem[0].length() > 14 ? popupItem[0].substring(0, 14) + "..." : popupItem[0];
        autoWireDropDownButton
                .add(new InsertionAction("<html><table border=0 cellpadding=0 cellspacing=0><tr><td width=100>"
                        + shortcut + "</td><td>" + popupItem[1] + "</td></tr></table></html>", popupItem[0]));
    }
    c.insets = new Insets(4, 0, 4, 0);
    c.gridx = 1;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    regexpPanel.add(autoWireDropDownButton.getDropDownArrowButton(), c);

    // make delete button
    c.insets = new Insets(4, 0, 4, 4);
    c.gridx = 2;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    JButton clearRegexpTextFieldButton = new JButton(SwingTools.createIcon("16/delete2.png"));
    clearRegexpTextFieldButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            regexpTextField.setText("");
            fireRegularExpressionUpdated();
            regexpTextField.requestFocusInWindow();
        }
    });

    regexpPanel.add(clearRegexpTextFieldButton, c);

    errorMessage = new JLabel(NO_ERROR_MESSAGE, NO_ERROR_ICON, SwingConstants.LEFT);
    errorMessage.setFocusable(false);
    c.insets = new Insets(4, 8, 4, 4);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    regexpPanel.add(errorMessage, c);

    // create replacement panel
    JPanel replacementPanel = new JPanel(new GridBagLayout());
    replacementPanel.setBorder(createTitledBorder(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.border")));

    JPanel testerPanel = new JPanel(new GridBagLayout());

    c.insets = new Insets(4, 4, 4, 0);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    replacementPanel.add(replacementTextField, c);

    // create inline search panel
    JPanel inlineSearchPanel = new JPanel(new GridBagLayout());

    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    inlineSearchPanel.add(
            new JLabel(
                    I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.search")),
            c);

    c.insets = new Insets(0, 0, 0, 0);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    inlineSearchPanel.add(new JScrollPane(new JTextPane(inlineSearchDocument)), c);

    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    inlineSearchPanel.add(
            new JLabel(
                    I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.replaced")),
            c);

    c.insets = new Insets(0, 0, 0, 0);
    c.gridx = 0;
    c.gridy = 3;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    JTextPane replaceTextPane = new JTextPane(inlineReplaceDocument);
    replaceTextPane.setEditable(false);
    inlineSearchPanel.add(new JScrollPane(replaceTextPane), c);

    // create regexp options panel
    ItemListener defaultOptionListener = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            fireRegexpOptionsChanged();
        }
    };

    cbCaseInsensitive = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive"));
    cbCaseInsensitive.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive.tip"));
    cbCaseInsensitive.addItemListener(defaultOptionListener);

    cbMultiline = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode"));
    cbMultiline.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode.tip"));
    cbMultiline.addItemListener(defaultOptionListener);

    cbDotall = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode"));
    cbDotall.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode.tip"));
    cbDotall.addItemListener(defaultOptionListener);

    cbUnicodeCase = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case"));
    cbUnicodeCase.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case.tip"));
    cbUnicodeCase.addItemListener(defaultOptionListener);

    JPanel regexpOptionsPanelWrapper = new JPanel(new BorderLayout());
    JPanel regexpOptionsPanel = new JPanel(new GridBagLayout());
    regexpOptionsPanelWrapper.add(regexpOptionsPanel, BorderLayout.NORTH);

    c.insets = new Insets(12, 4, 0, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    regexpOptionsPanel.add(cbMultiline, c);
    c.insets = new Insets(8, 4, 0, 4);
    c.gridy = 1;
    regexpOptionsPanel.add(cbCaseInsensitive, c);
    c.gridy = 2;
    regexpOptionsPanel.add(cbUnicodeCase, c);
    c.gridy = 3;
    regexpOptionsPanel.add(cbDotall, c);

    // create tabbed panel
    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    testExp = new JTabbedPane();
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.inline_search.title"),
            new JScrollPane(inlineSearchPanel));
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.result_list.title"),
            new JScrollPane(regexpFindingsList));
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.regexp_options.title"),
            regexpOptionsPanelWrapper);
    testerPanel.add(testExp, c);

    JPanel groupPanel = new JPanel(new GridBagLayout());
    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    groupPanel.add(regexpPanel, c);

    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    groupPanel.add(replacementPanel, c);

    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    groupPanel.add(testerPanel, c);

    panel.add(groupPanel, 1, 0);

    if (supportsItems) {
        // item shortcuts list
        itemShortcutsList = new JList<String>(items.toArray(new String[items.size()]));
        itemShortcutsList.setToolTipText(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.tip"));
        itemShortcutsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        itemShortcutsList.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    String text = regexpTextField.getText();
                    int cursorPosition = regexpTextField.getCaretPosition();
                    int index = itemShortcutsList.getSelectedIndex();
                    if (index > -1 && index < itemShortcutsList.getModel().getSize()) {
                        String insertionString = itemShortcutsList.getModel().getElementAt(index).toString();
                        String newText = text.substring(0, cursorPosition) + insertionString
                                + (cursorPosition < text.length() ? text.substring(cursorPosition) : "");
                        regexpTextField.setText(newText);
                        regexpTextField.setCaretPosition(cursorPosition + insertionString.length());
                        regexpTextField.requestFocus();
                        fireRegularExpressionUpdated();
                    }
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }
        });
        JScrollPane itemShortcutsPane = new JScrollPane(itemShortcutsList);
        itemShortcutsPane.setBorder(createTitledBorder(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.border")));

        // matched items list
        matchedItemsListModel = new DefaultListModel<String>();
        JList<String> matchedItemsList = new JList<String>(matchedItemsListModel);
        matchedItemsList.setToolTipText(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.tip"));
        // add custom cell renderer to disallow selections
        matchedItemsList.setCellRenderer(new DefaultListCellRenderer() {

            private static final long serialVersionUID = -5795848004756768378L;

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index,
                    boolean isSelected, boolean cellHasFocus) {
                return super.getListCellRendererComponent(list, value, index, false, false);
            }
        });
        JScrollPane matchedItemsPanel = new JScrollPane(matchedItemsList);
        matchedItemsPanel.setBorder(createTitledBorder(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.border")));

        // item panel on right side of dialog
        JPanel itemPanel = new JPanel(createGridLayout(1, 2));
        itemPanel.add(itemShortcutsPane, 0, 0);
        itemPanel.add(matchedItemsPanel, 0, 1);

        panel.add(itemPanel, 0, 1);
    }

    okButton = makeOkButton("regexp_property_dialog_apply");
    fireRegularExpressionUpdated();

    layoutDefault(panel, supportsItems ? NORMAL : NARROW, okButton, makeCancelButton());
}

From source file:com.vgi.mafscaling.LogView.java

private void createLogViewPanel() {
    logViewPanel = new JPanel();
    GridBagLayout gbl_logViewPanel = new GridBagLayout();
    gbl_logViewPanel.columnWidths = new int[] { 0 };
    gbl_logViewPanel.rowHeights = new int[] { 0, 0 };
    gbl_logViewPanel.columnWeights = new double[] { 1.0 };
    gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 };
    logViewPanel.setLayout(gbl_logViewPanel);
    try {//from  w  w w.j a v a  2  s .co  m
        logDataTable = new DBTable();
        logDataTable.copyColumnHeaderNames = true;
        logDataTable.defaultClickCountToStartEditor = 2;
        logDataTable.doNotUseDatabaseSort = true;
        logDataTable.listenKeyPressEventsWholeWindow = true;
        logDataTable.createControlPanel(DBTable.READ_NAVIGATION);
        logDataTable.enableExcelCopyPaste();
        logDataTable.setSortEnabled(false);
        logDataTable.setSkin(new TableSkin());
        logDataTable.refresh(new String[1][25]);
        logDataTable.setComparator(new DoubleComparator());
        logDataTable.getTable().setCellSelectionEnabled(true);
        logDataTable.getTable().setColumnSelectionAllowed(true);
        logDataTable.getTable().setRowSelectionAllowed(true);
        logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3));
        rowTextField.setPreferredSize(null);
        rowTextField.setColumns(5);

        GridBagConstraints gbc_logDataTable = new GridBagConstraints();
        gbc_logDataTable.insets = insets0;
        gbc_logDataTable.anchor = GridBagConstraints.PAGE_START;
        gbc_logDataTable.fill = GridBagConstraints.BOTH;
        gbc_logDataTable.gridx = 0;
        gbc_logDataTable.gridy = 0;
        logViewPanel.add(logDataTable, gbc_logDataTable);
        listModel = new DefaultListModel<JLabel>();

        selectionCombo.removeAllItems();
        String name;
        JTableHeader tableHeader = logDataTable.getTableHeader();
        for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
            Column col = logDataTable.getColumn(i);
            col.setNullable(true);
            col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader));
            name = col.getHeaderValue().toString();
            selectionCombo.addItem(name);
            listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT));
        }

        JList<JLabel> menuList = new JList<JLabel>(listModel);
        menuList.setOpaque(false);
        menuList.setCellRenderer(new ImageListCellRenderer());
        menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        menuList.setLayoutOrientation(JList.VERTICAL);
        menuList.setFixedCellHeight(25);
        menuList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    if (e.getClickCount() == 1 && colors.size() > 0) {
                        JList<?> list = (JList<?>) e.getSource();
                        int index = list.locationToIndex(e.getPoint());
                        if (index >= 0) {
                            int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index);
                            Column col = logDataTable.getColumn(colIdx);
                            if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) {
                                CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col
                                        .getHeaderRenderer();
                                JLabel label = (JLabel) list.getModel().getElementAt(index);
                                CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon();
                                checkIcon.setChecked(!checkIcon.isChecked());
                                if (checkIcon.isChecked()) {
                                    checkIcon.setColor(colors.pop());
                                    JTable table = logDataTable.getTable();
                                    TableModel model = table.getModel();
                                    addXYSeries(model, index, col.getHeaderValue().toString(),
                                            checkIcon.getColor());
                                } else {
                                    colors.push(checkIcon.getColor());
                                    checkIcon.setColor(renderer.getDefaultColor());
                                    removeXYSeries(index);
                                }
                                list.repaint();
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

        headerScrollPane = new JScrollPane(menuList);
        GridBagConstraints gbc_headersTree = new GridBagConstraints();
        gbc_headersTree.insets = insets0;
        gbc_headersTree.anchor = GridBagConstraints.PAGE_START;
        gbc_headersTree.fill = GridBagConstraints.BOTH;
        gbc_headersTree.gridx = 0;
        gbc_headersTree.gridy = 1;

        logViewPanel.add(headerScrollPane, gbc_headersTree);
        headerScrollPane.setVisible(false);

    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e);
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

@SuppressWarnings("unchecked")
private void addRenderers() {
    try {/* w  ww . jav  a2s  . c  o m*/
        setDefaultRenderer(Class.forName("java.lang.Object"), new JBDefaultTableCellRenderer());
        setDefaultRenderer(Class.forName("java.util.Collection"), new CollectionRenderer());

        final JList<Object> list = new JList<Object>();
        list.setVisibleRowCount(3);
        list.setOpaque(true);
        list.setCellRenderer(new ListDefaultRenderer());

        list.addListSelectionListener(new ListSelectionListener() {
            @SuppressWarnings({ "static-access", "unused" })
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    Object obj = list.getSelectedValue();
                    obj = RegistryObjectsTable.this.convertValue(obj);

                    if (obj instanceof URL) {
                        HyperLinker.displayURL(obj.toString());
                    } else if (obj instanceof String) {
                        //Check if URL is valid
                        URL _url = null;

                        try {
                            _url = new URL(obj.toString());
                            HyperLinker.displayURL(obj.toString());
                        } catch (MalformedURLException exc) {
                            //No need to do anything. It is normal for text to not be a URL
                            _url = null;
                        }
                    }
                }
            }
        });

        JScrollPane listPane = new JScrollPane(list);
        setDefaultEditor(Class.forName("java.util.Collection"), new JBDefaultCellEditor(listPane));

        HyperLinkLabel hyperLinkLabel = new HyperLinkLabel();
        hyperLinkLabel.setHorizontalAlignment(SwingConstants.TRAILING);
        setDefaultEditor(Class.forName("java.lang.Object"), new JBDefaultCellEditor(hyperLinkLabel));
    } catch (ClassNotFoundException e) {
        return;
    }
}

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JList buildJList(final Dimension dimension, final Object[] items, final JList list,
        final boolean sort) {
    if (items == null) {
        return null;
    }/*from   w  w  w  . j  a v a  2s .  c o  m*/
    list.setModel(new DefaultListModel() {

        @Override
        public void addElement(Object obj) {
            boolean inserted = false;
            if (sort) {
                for (int i = 0; i < this.getSize() && !inserted; i++) {
                    try {
                        final String comparator = ((obj == null) ? "" : obj.toString());
                        if (this.get(i).toString().compareTo(comparator) > 0) {
                            this.add(i, obj);
                            inserted = true;
                        }
                    } catch (Throwable t) {
                        log.error("Error al ordenar a " + obj + " y no lo incluimos", t);
                        inserted = true;
                    }
                }
            }
            if (!inserted) {
                super.addElement(obj);
            }
        }
    });
    log.trace("Lista con " + items.length + " objetos");
    for (Object obj : items) {
        ((DefaultListModel) list.getModel()).addElement(obj);
    }
    list.setCellRenderer(new DefaultListCellRenderer() {

        private static final long serialVersionUID = -987995602141400182L;

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            JLabel c = new JLabel();
            c.setText(value.toString());

            if (isSelected) {
                c.setOpaque(true);
                c.setBackground(Color.YELLOW);
            }
            return c;
        }
    });
    list.setMinimumSize(dimension);
    list.setFixedCellHeight(22);
    return list;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public JPanel createList() {
    JPanel p = new JPanel(new BorderLayout());
    final VFSJFileChooser fileChooser = getFileChooser();
    final JList aList = new JList() {
        @Override//w w  w  .j a  v a 2  s .c om
        public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
            ListModel model = getModel();
            int max = model.getSize();

            if ((prefix == null) || (startIndex < 0) || (startIndex >= max)) {
                throw new IllegalArgumentException();
            }

            // start search from the next element before/after the selected element
            boolean backwards = (bias == Position.Bias.Backward);

            for (int i = startIndex; backwards ? (i >= 0) : (i < max); i += (backwards ? (-1) : 1)) {
                String filename = fileChooser.getName((FileObject) model.getElementAt(i));

                if (filename.regionMatches(true, 0, prefix, 0, prefix.length())) {
                    return i;
                }
            }

            return -1;
        }
    };

    aList.setCellRenderer(new FileRenderer());
    aList.setLayoutOrientation(JList.VERTICAL_WRAP);

    // 4835633 : tell BasicListUI that this is a file list
    aList.putClientProperty("List.isFileList", Boolean.TRUE);

    if (listViewWindowsStyle) {
        aList.addFocusListener(repaintListener);
    }

    updateListRowCount(aList);

    getModel().addListDataListener(new ListDataListener() {
        public void intervalAdded(ListDataEvent e) {
            updateListRowCount(aList);
        }

        public void intervalRemoved(ListDataEvent e) {
            updateListRowCount(aList);
        }

        public void contentsChanged(ListDataEvent e) {
            if (isShowing()) {
                clearSelection();
            }

            updateListRowCount(aList);
        }
    });

    getModel().addPropertyChangeListener(this);

    if (fileChooser.isMultiSelectionEnabled()) {
        aList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    } else {
        aList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    aList.setModel(getModel());

    aList.addListSelectionListener(createListSelectionListener());
    aList.addMouseListener(getMouseHandler());

    JScrollPane scrollpane = new JScrollPane(aList);

    if (listViewBackground != null) {
        aList.setBackground(listViewBackground);
    }

    if (listViewBorder != null) {
        scrollpane.setBorder(listViewBorder);
    }

    p.add(scrollpane, BorderLayout.CENTER);

    return p;
}

From source file:fs.MainWindow.java

public void GenerateTable(Object[][] data, String title, String subtitle, final String[] titles) {
    JFrame window = new JFrame(title);
    window.setLayout(new java.awt.BorderLayout(5, 5));
    JLabel label = new JLabel(subtitle);
    label.setFont(new java.awt.Font("Tahoma", 1, 12));
    label.setForeground(new java.awt.Color(0, 0, 255));
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setOpaque(true);/*from   w w  w.j  a va2 s .c om*/
    label.setPreferredSize(new java.awt.Dimension(50, 30));

    ListModel lm = new AbstractListModel() {

        String headers[] = titles;

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

        @Override
        public Object getElementAt(int index) {
            return headers[index];
        }
    };

    //        String[] titles = getClasses();
    JList rowHeader = new JList(lm);
    rowHeader.setFixedCellWidth(50);
    JTable jTable = new JTable(data, titles);
    rowHeader.setFixedCellHeight(jTable.getRowHeight());
    rowHeader.setCellRenderer(new RowHeaderRenderer(jTable));
    JScrollPane scroll = new JScrollPane(jTable);
    scroll.setRowHeaderView(rowHeader);
    getContentPane().add(scroll, BorderLayout.CENTER);

    jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jTable.setAlignmentX(JTable.CENTER_ALIGNMENT);

    window.add(label, java.awt.BorderLayout.NORTH);
    window.add(scroll, java.awt.BorderLayout.CENTER);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    window.setBounds((screenSize.width - 800) / 2, (screenSize.height - 270) / 2, 800, 270);
    window.setVisible(true);
}