Java Code Examples for javax.swing.JList#getCellRenderer()

The following examples show how to use javax.swing.JList#getCellRenderer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the given point is within the actual bounds of the
 * JList item at index (not just inside the cell).
 */
private static <T> boolean pointIsInActualBounds(JList<T> list, int index,
                                            Point point) {
    ListCellRenderer<? super T> renderer = list.getCellRenderer();
    T value = list.getModel().getElementAt(index);
    Component item = renderer.getListCellRendererComponent(list,
                      value, index, false, false);
    Dimension itemSize = item.getPreferredSize();
    Rectangle cellBounds = list.getCellBounds(index, index);
    if (!item.getComponentOrientation().isLeftToRight()) {
        cellBounds.x += (cellBounds.width - itemSize.width);
    }
    cellBounds.width = itemSize.width;

    return cellBounds.contains(point);
}
 
Example 2
Source File: JListItemJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Component getRendererComponent(JList list, int item) {
    Object value = list.getModel().getElementAt(item);
    ListCellRenderer cellRenderer = list.getCellRenderer();
    Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, item, false, false);
    if (rendererComponent == null) {
        return null;
    }
    if (rendererComponent instanceof JComponent) {
        ((JComponent) rendererComponent).putClientProperty("jlist", (JList) list);
        ((JComponent) rendererComponent).putClientProperty("item", item);
    }
    return rendererComponent;
}
 
Example 3
Source File: TableUISupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void connectAvailable(JList availableTablesList, TableClosure tableClosure, FilterAvailable filter) {
    availableTablesList.setModel(new AvailableTablesModel(tableClosure));

    if (!(availableTablesList.getCellRenderer() instanceof AvailableTableRenderer)) {
        availableTablesList.setCellRenderer(new AvailableTableRenderer(filter));
    } else {
        AvailableTableRenderer renderer = (AvailableTableRenderer) availableTablesList.getCellRenderer();
        renderer.updateFilter(filter);
    }
}
 
Example 4
Source File: TableUISupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void connectSelected(JList selectedTablesList, TableClosure tableClosure) {
    selectedTablesList.setModel(new SelectedTablesModel(tableClosure));

    if (!(selectedTablesList.getCellRenderer() instanceof SelectedTableRenderer)) {
        selectedTablesList.setCellRenderer(new SelectedTableRenderer());
    }
}
 
Example 5
Source File: ViewTooltips.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void showJList (JScrollPane view, Point pt) {
    JList list = (JList) view.getViewport().getView();
    Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
    int row = list.locationToIndex(p);
    if (row == -1) {
        hide();
        return;
    }
    Rectangle bds = list.getCellBounds(row, 
            row);
    //GetCellBounds returns a width that is the
    //full component width;  we want only what
    //the renderer really needs.
    ListCellRenderer ren = list.getCellRenderer();
    Dimension rendererSize = 
            ren.getListCellRendererComponent(list, 
            list.getModel().getElementAt(row), 
            row, false, false).getPreferredSize();
    
    bds.width = rendererSize.width;
    if (bds == null || !bds.contains(p)) {
        hide();
        return;
    }
    if (setCompAndRow (list, row)) {
        Rectangle visible = getShowingRect (view);
        Rectangle[] rects = getRects (bds, visible);
        if (rects.length > 0) {
            ensureOldPopupsHidden();
            painter.configure(
                    list.getModel().getElementAt(row), 
                    view, list, row);
            showPopups (rects, bds, visible, list, view);
        } else {
            hide();
        }
    }
}
 
Example 6
Source File: TableUISupport.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public static void connectAvailable(JList availableTablesList, TableClosure tableClosure) {
        availableTablesList.setModel(new AvailableTablesModel(tableClosure));
        if (!(availableTablesList.getCellRenderer() instanceof AvailableTableRenderer)) {
            availableTablesList.setCellRenderer(new AvailableTableRenderer());
        }
//        else {
//            AvailableTableRenderer renderer = (AvailableTableRenderer) availableTablesList.getCellRenderer();
//            renderer.updateFilter(filter);
//        }
    }
 
Example 7
Source File: TableUISupport.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public static void connectSelected(JList selectedTablesList, TableClosure tableClosure) {
    selectedTablesList.setModel(new SelectedTablesModel(tableClosure));

    if (!(selectedTablesList.getCellRenderer() instanceof SelectedTableRenderer)) {
        selectedTablesList.setCellRenderer(new SelectedTableRenderer());
    }
}
 
Example 8
Source File: JmxConnectionConfigurator.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void initComponents() {
    okButton = new JButton(NbBundle.getMessage(JmxConnectionConfigurator.class, "LBL_OK"));    // NOI18N

    hintLabel = new JLabel("") { // NOI18N
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.height = Math.max(d.height, okButton.getPreferredSize().height);
            return d;
        }
    };
    hintLabel.setForeground(UIManager.getColor("Label.disabledForeground")); // NOI18N

    setLayout(new BorderLayout());

    connectionTypeLabel = new JLabel();
    Mnemonics.setLocalizedText(connectionTypeLabel,
            NbBundle.getMessage(JmxConnectionConfigurator.class, "LBL_Connection_type")); // NOI18N
    createBorder(connectionTypeLabel, BorderFactory.createEmptyBorder(15, 10, 0, 10));
    add(connectionTypeLabel, BorderLayout.NORTH);

    connectionTypeListModel = new DefaultListModel();
    connectionTypeList = new JList(connectionTypeListModel) {
        public String getToolTipText(MouseEvent evt) {
            JmxConnectionCustomizer cust = getCustomizer(evt.getPoint());
            return cust == null ? null : cust.getPropertiesDescription();
        }

    };
    connectionTypeLabel.setLabelFor(connectionTypeList);
    connectionTypeList.setSelectionModel(new DefaultListSelectionModel() {
        public void removeSelectionInterval(int i1, int i2) {}
    });
    connectionTypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final ListCellRenderer defaultRenderer = connectionTypeList.getCellRenderer();
    Component c = defaultRenderer.getListCellRendererComponent(connectionTypeList, "X", 0, false, false); // NOI18N
    connectionTypeList.setFixedCellHeight(c.getPreferredSize().height + 2);
    connectionTypeList.setCellRenderer(new ListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return defaultRenderer.getListCellRendererComponent(list, " " + value + " ", index, isSelected, cellHasFocus); // NOI18N
        }
    });
    connectionTypeScroll = new JScrollPane(connectionTypeList,
                                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
        public Dimension getPreferredSize() {
            Dimension preferredSize = super.getPreferredSize();
            preferredSize.width = Math.min(preferredSize.width, 300);
            preferredSize.width = Math.max(preferredSize.width, 120);
            return preferredSize;
        }
    };
    createBorder(connectionTypeScroll, BorderFactory.createEmptyBorder(5, 10, 0, 0));
    add(connectionTypeScroll, BorderLayout.WEST);

    customizerPanel = new JPanel(new BorderLayout());
    customizerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    customizerPanelScroll = new ScrollableContainer(customizerPanel,
            ScrollableContainer.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollableContainer.HORIZONTAL_SCROLLBAR_NEVER);
    customizerPanelScroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 5));
    add(customizerPanelScroll, BorderLayout.CENTER);
}