Java Code Examples for javax.swing.JList

The following are top voted examples for showing how to use javax.swing.JList. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Cognizant-Intelligent-Test-Scripter   File: JSList.java   View source code 8 votes vote down vote up
public ListPanel(FilterModel fltrmodel, Function<T, String> mapper) {
    setLayout(new java.awt.BorderLayout());
    JScrollPane sp = new javax.swing.JScrollPane();
    list = new JList();
    list.setModel(fltrmodel);
    list.setCellRenderer(new CheckBoxListRenderer(mapper));
    sp.setViewportView(list);
    add(sp, BorderLayout.CENTER);
    list.setSelectionModel(new MultiSelectionModel(this::onSelect));
    list.addKeyListener(onDelete());
    list.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ctrl A"), "SelectAll");
    list.getActionMap().put("SelectAll", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            list.setSelectionInterval(0, list.getModel().getSize() - 1);
        }
    });
}
 
Example 2
Project: incubator-netbeans   File: FoldOptionsPanel.java   View source code 7 votes vote down vote up
/**
 * Creates new form FoldOptionsPanel
 */
public FoldOptionsPanel(FoldOptionsController ctrl) {
    this.ctrl = ctrl;
    initComponents();
    
    langSelect.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof String[]) {
                value = ((String[])value)[1];
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates.
        }
    });
    langSelect.addActionListener(this);
    contentPreview.addActionListener(this);
    foldedSummary.addActionListener(this);
    
    // preferences should be set as a reaction to index selection
}
 
Example 3
Project: DocIT   File: DeptView.java   View source code 6 votes vote down vote up
public DeptView(Controller controller) {
	this.controller = controller;
	frame = new JFrame();
	namePanel = new JPanel(new GridLayout(1, 2, 0, 0));
	managerPanel = new JPanel(new GridLayout(1, 2, 66, 0));
	employeePanel = new JPanel(new GridLayout(1, 2, 30, 0));
	subDeptPanel = new JPanel(new GridLayout(1, 2, 20, 0));
	salaryPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
	buttonPanel = new JPanel(new GridLayout(1, 3, 20, 0));
	subDeptLabel = new JLabel();
	salaryLabel = new JLabel();
	cutButton = new JButton();
	saveButton = new JButton();
	okButton = new JButton();
	cancelButton = new JButton();
	nameField = new JTextField();
	managerButton = new JButton();
	employeeListModel = new DefaultListModel();
	subDeptListModel = new DefaultListModel();
	employeeList = new JList(employeeListModel);
	subDeptList = new JList(subDeptListModel);
	init();
}
 
Example 4
Project: java-swing-template   File: IconListCellRenderer.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (value != null) {
        setText(value.toString());
        ImageIcon imageIcon = new javax.swing.ImageIcon(getClass().getResource("/app/resources/" + icon_resource));
        setIcon(imageIcon);
    }

    setForeground(list.getForeground());
    setBackground(list.getBackground());

    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    }

    return this;
}
 
Example 5
Project: incubator-netbeans   File: ActionMappings.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value,
                                              int arg2, boolean arg3,
                                              boolean arg4) {
    Component supers = super.getListCellRendererComponent(list, value, arg2, arg3, arg4);
    if (supers instanceof JLabel && value instanceof MappingWrapper) {
        MappingWrapper wr = (MappingWrapper)value;
        JLabel lbl = (JLabel)supers;
        if (wr.isUserDefined()) {
            lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
        } else {
            lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
        }
    }
    return supers;
}
 
Example 6
Project: ripme   File: QueueMenuMouseListener.java   View source code 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
        if (!(e.getSource() instanceof JList)) {
            return;
        }

        queueList = (JList) e.getSource();
        queueListModel = (DefaultListModel) queueList.getModel();
        queueList.requestFocus();

        int nx = e.getX();

        if (nx > 500) {
            nx = nx - popup.getSize().width;
        }
        popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
}
 
Example 7
Project: VISNode   File: ProcessBrowser.java   View source code 6 votes vote down vote up
/**
 * Creates the process list
 *
 * @return JComponent
 */
private JComponent buildList() {
    list = new JList<>();
    list.setCellRenderer(new CellRenderer(list.getCellRenderer()));
    list.setTransferHandler(new ProcessTransferHandler());
    list.setDragEnabled(true);
    list.setDropMode(DropMode.ON_OR_INSERT);
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() % 2 == 0) {
                ProcessInformationPane.showDialog(list.getSelectedValue());
            }
        }
    });
    return ScrollFactory.pane(list).create();
}
 
Example 8
Project: marathonv5   File: ListTransferHandler.java   View source code 6 votes vote down vote up
protected void cleanup(JComponent c, boolean remove) {
    if (remove && indices != null) {
        JList source = (JList) c;
        DefaultListModel model = (DefaultListModel) source.getModel();
        // If we are moving items around in the same list, we
        // need to adjust the indices accordingly, since those
        // after the insertion point have moved.
        if (addCount > 0) {
            for (int i = 0; i < indices.length; i++) {
                if (indices[i] > addIndex) {
                    indices[i] += addCount;
                }
            }
        }
        for (int i = indices.length - 1; i >= 0; i--) {
            model.remove(indices[i]);
        }
    }
    indices = null;
    addCount = 0;
    addIndex = -1;
}
 
Example 9
Project: incubator-netbeans   File: TaskPanel.java   View source code 6 votes vote down vote up
private void enableComponents (Component comp, boolean enable) {
    if (comp instanceof Container) {
        for (Component subComp : ((Container) comp).getComponents()) {
            enableComponents(subComp, enable);
        }
    }
    if ((comp instanceof JComboBox)
            || ((comp instanceof JTextComponent) && ((JTextComponent) comp).isEditable())
            || (comp instanceof AbstractButton) || (comp instanceof JList)) {
        if (enable) {
            Boolean b = enableMap.get(comp);
            if (b != null) {
                comp.setEnabled(b);
            }
        } else {
            enableMap.put(comp, comp.isEnabled());
            comp.setEnabled(false);
        }
    }
}
 
Example 10
Project: FreeCol   File: EndTurnDialog.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Component getListCellRendererComponent(JList<? extends UnitWrapper> list,
                                              UnitWrapper value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    imageLabel.setIcon(new ImageIcon(
        getImageLibrary().getSmallerUnitImage(value.unit)));
    nameLabel.setText(value.name);
    locationLabel.setText(value.location);

    JPanel panel = (isSelected) ? selectedPanel : itemPanel;
    panel.removeAll();
    panel.add(imageLabel, "center, width 40!, height 40!");
    panel.add(nameLabel, "split 2, flowy");
    panel.add(locationLabel);
    return panel;
}
 
Example 11
Project: rapidminer   File: PlotterPanel.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	String s = value.toString();
	setText(s);
	Icon icon = plotter.getIcon(index);
	if (icon != null) {
		setIcon(icon);
	}
	if (isSelected) {
		setBackground(list.getSelectionBackground());
		setForeground(list.getSelectionForeground());
	} else {
		setBackground(list.getBackground());
		setForeground(list.getForeground());
	}
	setEnabled(list.isEnabled());
	setFont(list.getFont());
	setOpaque(true);
	return this;
}
 
Example 12
Project: SER316-Ingolstadt   File: StickerDialog.java   View source code 6 votes vote down vote up
public Component getListCellRendererComponent(
	JList list,
	Object value,
	int index,
	boolean isSelected,
	boolean cellHasFocus) {
	/*
	 * if (isSelected) { setBackground(list.getSelectionBackground());
	 * setForeground(list.getSelectionForeground());
	 */
	if(index==7){
		this.setForeground(Color.WHITE);
	}
	else setForeground(list.getForeground());
	if ((index > -1) && (index < colors.length))
		setBackground(colors[index]);
	else
		setBackground(list.getBackground());
	//}
	setText(value.toString());
	return this;
}
 
Example 13
Project: incubator-netbeans   File: MultiDiffPanelController.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    String tooltip = null;
    if (value instanceof Revision) {
        Revision rev = (Revision) value;
        value = rev.toString(true);
        tooltip = rev.getFullMessage();
        if (tooltip != null) {
            tooltip = tooltip.replace("\r\n", "\n").replace("\n", "<br>"); //NOI18N
            StringBuilder sb = new StringBuilder("<html><p>"); //NOI18N
            sb.append(tooltip).append("</p></html>"); //NOI18N
            tooltip = sb.toString();
        }
    } else if (value instanceof String) {
        value = "<html><i>" + value + "</i></html>"; //NOI18N
        tooltip = Bundle.MSG_Revision_Select_Tooltip();
    }
    Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (comp instanceof JComponent) {
        ((JComponent) comp).setToolTipText(tooltip);
    }
    return comp;
}
 
Example 14
Project: incubator-netbeans   File: DashboardTransferHandler.java   View source code 6 votes vote down vote up
@Override
protected Transferable createTransferable(JComponent c) {
    if (c instanceof JList) {
        JList list = (JList) c;
        Object[] values = list.getSelectedValues();
        if (values == null || values.length == 0) {
            return null;
        }
        List<TaskNode> nodes = new ArrayList<TaskNode>(values.length);
        for (int i = 0; i < values.length; i++) {
            Object val = values[i];
            if (val instanceof TaskNode) {
                nodes.add((TaskNode) val);
            } else {
                return null;
            }
        }
        return new DashboardTransferable(nodes.toArray(new TaskNode[nodes.size()]));
    }
    return null;
}
 
Example 15
Project: SER316-Munich   File: StickerDialog.java   View source code 6 votes vote down vote up
public Component getListCellRendererComponent(
	JList list,
	Object value,
	int index,
	boolean isSelected,
	boolean cellHasFocus) {
	/*
	 * if (isSelected) { setBackground(list.getSelectionBackground());
	 * setForeground(list.getSelectionForeground());
	 */
	if(index==7){
		this.setForeground(Color.WHITE);
	}
	else setForeground(list.getForeground());
	if ((index > -1) && (index < colors.length))
		setBackground(colors[index]);
	else
		setBackground(list.getBackground());
	//}
	setText(value.toString());
	return this;
}
 
Example 16
Project: Equella   File: BaseEntityWithAddDialogTool.java   View source code 6 votes vote down vote up
public PluginDialog()
{
	listModel = new DefaultListModel<>();

	list = new JList<>();
	list.setModel(listModel);
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	for( String name : plugins.keySet() )
	{
		listModel.addElement(name);
	}

	setLayout(new BorderLayout());
	add(new JScrollPane(list));
}
 
Example 17
Project: incubator-netbeans   File: PlatformComponentFactory.java   View source code 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
    // #93658: GTK needs name to render cell renderer "natively"
    setName("ComboBox.listRenderer"); // NOI18N
    
    NbPlatform plaf = ((NbPlatform) value);
    // NetBeans.org modules doesn't have platform at all --> null
    String text = plaf == null ? "" : plaf.getLabel(); // NOI18N
    setText(text);
    
    if ( isSelected ) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());             
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    
    if (plaf != null && !plaf.isValid()) {
        setForeground(INVALID_PLAF_COLOR);
    }
    
    return this;
}
 
Example 18
Project: rapidminer   File: ConfirmLicensesDialog.java   View source code 6 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
    if(!e.getValueIsAdjusting()) {
        JList source = (JList)e.getSource();
        if(!source.isSelectionEmpty()) {
            if(!this.otherList.isSelectionEmpty()) {
                this.otherList.clearSelection();
            }

            PackageDescriptor desc = null;
            Object selectedValue = source.getSelectedValue();
            desc = (PackageDescriptor)selectedValue;

            try {
                ConfirmLicensesDialog.this.setLicensePaneContent(desc);
            } catch (Exception var6) {
                SwingTools.showSimpleErrorMessage("error_installing_update", var6, new Object[]{var6.getMessage()});
            }
        }
    }

}
 
Example 19
Project: incubator-netbeans   File: ProfilingPointsDisplayer.java   View source code 6 votes vote down vote up
private void initComponents() {
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    listModel = new DefaultListModel();
    list = new JList(listModel);
    list.getAccessibleContext().setAccessibleName(Bundle.ProfilingPointsDisplayer_ListAccessName());
    list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setVisibleRowCount(6);
    list.setCellRenderer(org.netbeans.modules.profiler.ppoints.Utils.getPresenterListRenderer());

    JScrollPane listScroll = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScroll.setPreferredSize(new Dimension(405, listScroll.getPreferredSize().height));

    add(listScroll, BorderLayout.CENTER);
}
 
Example 20
Project: incubator-netbeans   File: Utils.java   View source code 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                                              boolean cellHasFocus) {
    JLabel renderer = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    renderer.setBorder(BorderFactory.createEmptyBorder(1, 7, 1, 5));

    if (value instanceof ProfilingPoint) {
        boolean enabled = ((ProfilingPoint) value).isEnabled();
        renderer.setText(((ProfilingPoint) value).getName());
        renderer.setIcon(enabled ? ((ProfilingPoint) value).getFactory().getIcon() :
                                   ((ProfilingPoint) value).getFactory().getDisabledIcon());
        renderer.setEnabled(enabled);
    } else if (value instanceof ProfilingPointFactory) {
        renderer.setText(((ProfilingPointFactory) value).getType());
        renderer.setIcon(((ProfilingPointFactory) value).getIcon());
        renderer.setEnabled(true);
    } else {
        renderer.setIcon(null);
        renderer.setEnabled(true);
    }

    return renderer;
}
 
Example 21
Project: scorekeeperfrontend   File: TimeEntry.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> l, Object o, int i, boolean is, boolean f) 
{
	super.getListCellRendererComponent(l, o, i, is, f);

	if (o instanceof Run)
	{
		Run r = (Run)o;
		setText(NF.format(r.getRaw()));
	}
	else if (o instanceof Double)
	{
		setText(NF.format((Double)o));
	}

	setFont(font);
	return this;
}
 
Example 22
Project: incubator-netbeans   File: OnSaveTabPanel.java   View source code 6 votes vote down vote up
public OnSaveTabPanel() {
    initComponents();
    // Languages combobox renderer
    cboLanguage.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if ((value instanceof String) && selector != null) {
                value = selector.getLanguageName((String) value);
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    
    commonPanel = new OnSaveCommonPanel();
    commonPanelContainer.setLayout(new BorderLayout());
    commonPanelContainer.add(commonPanel, BorderLayout.WEST);
    
    customPanelContainer.setLayout(new BorderLayout());
}
 
Example 23
Project: incubator-netbeans   File: JShellOptions2.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    JLabel l = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    MemberDescription md = (MemberDescription)value;
    if (md == null) {
        return l;
    }
    l.setIcon(ElementIcons.getElementIcon(md.kind, md.modifiers));
    String n = md.name;
    if (md.kind == ElementKind.METHOD) {
        n += "()"; // NOI18N
    }
    l.setText(md.name);
    
    return l;
}
 
Example 24
Project: JavaGraph   File: FindReplaceDialog.java   View source code 6 votes vote down vote up
/** Returns the combo box for the label in the given type graph. */
private JComboBox<TypeLabel> getLabelComboBox(TypeGraph typeGraph) {
    final JComboBox<TypeLabel> result = new JComboBox<>();
    result.setFocusable(false);
    result.setRenderer(new DefaultListCellRenderer() {
        @SuppressWarnings("rawtypes")
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index,
            boolean isSelected, boolean cellHasFocus) {
            if (value instanceof TypeLabel) {
                value = HTMLConverter.HTML_TAG.on(((TypeLabel) value).toLine().toHTMLString());
            }
            return super.getListCellRendererComponent(list,
                value,
                index,
                isSelected,
                cellHasFocus);
        }
    });
    for (TypeLabel label : sortLabels(typeGraph.getLabels())) {
        if (!label.isDataType() && label != TypeLabel.NODE) {
            result.addItem(label);
        }
    }
    return result;
}
 
Example 25
Project: MaxSim   File: CheckRenderer.java   View source code 6 votes vote down vote up
public CheckRenderer(final JList<Object> list) {
    this.list = list;
    list.addMouseListener(
            new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    int index = list.locationToIndex(e.getPoint());
                    Point p2 = list.indexToLocation(index);
                    Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height);
                    if (r.contains(e.getPoint())) {
                        CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
                        node.setSelected(!node.isSelected());
                        list.repaint();
                        e.consume();
                    }
                }
            });

    this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5));
    startBackground = this.getBackground();
}
 
Example 26
Project: FreeCol   File: NegotiationDialog.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Component getListCellRendererComponent(JList<? extends Unit> list,
                                              Unit value, int index, boolean isSelected,
                                              boolean cellHasFocus) {
    setText((value == null) ? "" : value.getDescription());
    return this;
}
 
Example 27
Project: jmt   File: AllStationsParametersPanel.java   View source code 5 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
	JLabel label = new JLabel(stationData.getStationName(value), JMTImageLoader.loadImage(stationData.getStationType(value) + "Combo"),
			SwingConstants.LEFT);
	label.setOpaque(true);
	label.setBorder(new LineBorder(cellHasFocus ? Color.BLUE : Color.WHITE));
	label.setBackground(isSelected ? list.getSelectionBackground() : Color.WHITE);
	label.setForeground(isSelected ? list.getSelectionForeground() : Color.BLACK);
	label.setFont(isSelected ? label.getFont().deriveFont(Font.BOLD) : label.getFont().deriveFont(Font.ROMAN_BASELINE));
	return label;
}
 
Example 28
Project: incubator-netbeans   File: J2EEUtils.java   View source code 5 votes vote down vote up
public static ListCellRenderer getRenderer() {
    return 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 instanceof DBColumnInfo) {
                DBColumnInfo column = (DBColumnInfo)value;
                String label = column.getName() + (column.isValid() ? "" : " (" + column.getMessage() + ")"); // NOI18N
                setText(label);
                setEnabled(column.isValid());
            }
            return this;
        }
    };
}
 
Example 29
Project: incubator-netbeans   File: AddPropertyPanel.java   View source code 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
    // #89393: GTK needs name to render cell renderer "natively"
    setName("ComboBox.listRenderer"); // NOI18N

    if (value != null) {
        String text = (String) value;
        text = text.substring(text.lastIndexOf('.') + 1);
        setText(text);
        setIcon(getClassIcon());
    } else {
        setText(null);
        setIcon(getEmptyIcon());
    }
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
 
Example 30
Project: freecol   File: FreeColComboBoxRenderer.java   View source code 5 votes vote down vote up
/**
 * Returns a {@code ListCellRenderer} for the given
 * {@code JList}.
 *
 * @param list The {@code JList}.
 * @param value The list cell.
 * @param index The index in the list.
 * @param isSelected {@code true} if the given list cell is selected.
 * @param hasFocus {@code false} if the given list cell has the focus.
 * @return The {@code ListCellRenderer}
 */
@Override
public Component getListCellRendererComponent(JList<? extends T> list,
                                              T value, int index,
                                              boolean isSelected,
                                              boolean hasFocus) {
    JLabel c = isSelected ? SELECTED_COMPONENT : NORMAL_COMPONENT;
    c.setForeground(list.getForeground());
    c.setFont(list.getFont());
    setLabelValues(c, value);
    return c;
}
 
Example 31
Project: MailCopier   File: ReceiveForm.java   View source code 5 votes vote down vote up
private JScrollPane get_MessagesList() {
    if(messagesList == null) {
        messagesList = new JList<String>();
        messagesList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        messagesList.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent evt) {
                    int keyCode = evt.getKeyCode();
                    if(keyCode == KeyEvent.VK_DELETE) {
                        if(receive_butt.getText().equals(pManager.get_String("pause"))) {
                            String title = pManager.get_String("warning");
                            String message = pManager.get_String("receiver_delete_message");
                            boolean sound = pManager.get_sounds_status();
                            Notification.show(title, message, sound, Notification.WARNING_MESSAGE);
                        } else {
                            int[] indices = messagesList.getSelectedIndices();
                            mailCopier.deleteMessages(indices);
                        }
                    }
                }
            });
        mailCopier.addCopierListener(new CopierAdapter() {
                public void messagesListChanged(LinkedList<String> messages) {
                    messagesList.setListData(messages.toArray(new String[messages.size()]));
                }
            });
    }
    JScrollPane scroll = new JScrollPane(messagesList);
    scroll.setPreferredSize(new Dimension(100, 150));
        
    return scroll;
}
 
Example 32
Project: openjdk-jdk10   File: JListOperator.java   View source code 5 votes vote down vote up
/**
 * Maps {@code JList.getSelectedValue()} through queue
 */
public Object getSelectedValue() {
    return (runMapping(new MapAction<Object>("getSelectedValue") {
        @Override
        public Object map() {
            return ((JList) getSource()).getSelectedValue();
        }
    }));
}
 
Example 33
Project: incubator-netbeans   File: ColorEditor.java   View source code 5 votes vote down vote up
/** This is the only method defined by ListCellRenderer.  We just
 * reconfigure the Jlabel each time we're called.
 */
public Component getListCellRendererComponent (
    JList list,
    Object value,            // value to display
    int index,               // cell index
    boolean isSelected,      // is the cell selected
    boolean cellHasFocus     // the list and the cell have the focus
) {
    this.index = index;
    selected = isSelected;
    hasFocus = cellHasFocus;
    getAccessibleContext().setAccessibleName(names[index]);
    return this;
}
 
Example 34
Project: freecol   File: UnitType.java   View source code 5 votes vote down vote up
@Override
public int getMinimumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
    ListModel<BuildableType> buildQueue = buildQueueList.getModel();
    if (colony.canBuild(this)) return 0;
    for (int index = 0; index < buildQueue.getSize(); index++) {
        if (buildQueue.getElementAt(index).hasAbility(Ability.BUILD, this)) return index + 1;
    }
    return UNABLE_TO_BUILD;
}
 
Example 35
Project: VISNode   File: ProcessBrowser.java   View source code 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends Class<Process>> list, Class<Process> value, int index, boolean isSelected, boolean cellHasFocus) {
    ProcessMetadata metadata = processMetadata.get(value);
    // Title label
    JLabel label = (JLabel) defaultRenderer.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);
    label.setText(metadata.getName());
    label.setFont(new Font("Segoe UI", Font.BOLD, 12));
    // Description label
    JLabel description = new JLabel(metadata.getDescription());
    description.setForeground(description.getForeground());
    description.setBorder(BorderFactory.createEmptyBorder(1, 10, 3, 3));
    description.setFont(new Font("Segoe UI", Font.PLAIN, 10));
    if (metadata.getDescription() == null || metadata.getDescription().isEmpty()) {
        description.setText("<No description specified>");
        description.setForeground(description.getForeground().darker());
    }
    // Builds the component
    JPanel component = new JPanel();
    component.setLayout(new BorderLayout());
    component.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
    if (isSelected) {
        component.setBackground(new Color(0xEDEDED));
    } else {
        if (index % 2 == 0) {
            component.setBackground(new Color(0x555555));
        }
    }
    component.add(label);
    component.add(description, BorderLayout.SOUTH);
    component.setOpaque(true);
    component.setForeground(description.getForeground());
    return component;
}
 
Example 36
Project: incubator-netbeans   File: SummaryCellRenderer.java   View source code 5 votes vote down vote up
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    AbstractSummaryView.ShowLessEventsItem item = (AbstractSummaryView.ShowLessEventsItem) value;
    id = item.getItemId();
    if (linkerSupport.getLinker(ShowLessFilesLink.class, id) == null) {
        linkerSupport.add(new ShowLessFilesLink(item.getParent()), id);
    }
    StringBuilder sb = new StringBuilder("<html><a href=\"expand\">"); //NOI18N
    String label = NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowLessFiles"); //NOI18N
    if (isSelected) {
        Component c = dlcr.getListCellRendererComponent(list, "<html><a href=\"expand\">ACTION_NAME</a>", index, isSelected, cellHasFocus); //NOI18N
        sb.append("<font color=\"").append(getColorString(c.getForeground())).append("\">") //NOI18N
                .append(label).append("</font>"); //NOI18N
    } else if (LINK_COLOR != null) {
        sb.append("<font color=\"").append(getColorString(LINK_COLOR)).append("\">") //NOI18N
                .append(label).append("</font>"); //NOI18N
    } else {
        sb.append(label);
    }
    sb.append("</a></html>"); //NOI18N
    comp = dlcr.getListCellRendererComponent(list, sb.toString(), index, isSelected, cellHasFocus);
    removeAll();
    add(comp);
    comp.setMaximumSize(comp.getPreferredSize());
    setBackground(comp.getBackground());
    return this;
}
 
Example 37
Project: incubator-netbeans   File: RepositorySelectorBuilder.java   View source code 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) 
{
    String text;
    Image icon = null;
    if (value == null) {
        text = null;
    } else if (value instanceof RepositoryImpl) {
        RepositoryImpl repo = (RepositoryImpl) value;
        text = repo.getDisplayName();
        icon = repo.getIcon();
    } else if (value instanceof NewRepositoryInfo) {
        String connectorName = ((NewRepositoryInfo) value).connector
                               .getDisplayName();
        text = newConnectionFormat.format(new Object[] {connectorName});
        icon = ((NewRepositoryInfo) value).connector.getIcon();
    } else {
        assert false;
        text = "???";                                           //NOI18N
    }
    Component r = defaultRenderer.getListCellRendererComponent(list,
                                                                 text,
                                                                 index,
                                                                 isSelected,
                                                                 cellHasFocus);
    if (r instanceof JLabel) {
        JLabel label = (JLabel) r;
        label.setIcon(new ImageIcon(icon));
    }
    return r;
}
 
Example 38
Project: incubator-netbeans   File: GenerateCodePanel.java   View source code 5 votes vote down vote up
public Renderer(JList list) {
    setFont(list.getFont());
    fgColor = list.getForeground();
    bgColor = list.getBackground();
    bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();
}
 
Example 39
Project: jdk8u-jdk   File: MultiListUI.java   View source code 5 votes vote down vote up
/**
 * Invokes the <code>getCellBounds</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle getCellBounds(JList a, int b, int c) {
    Rectangle returnValue =
        ((ListUI) (uis.elementAt(0))).getCellBounds(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((ListUI) (uis.elementAt(i))).getCellBounds(a,b,c);
    }
    return returnValue;
}
 
Example 40
Project: OpenJSharp   File: MultiListUI.java   View source code 5 votes vote down vote up
/**
 * Invokes the <code>indexToLocation</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Point indexToLocation(JList a, int b) {
    Point returnValue =
        ((ListUI) (uis.elementAt(0))).indexToLocation(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((ListUI) (uis.elementAt(i))).indexToLocation(a,b);
    }
    return returnValue;
}