List of usage examples for javax.swing JList getSelectionForeground
public Color getSelectionForeground()
From source file:MyCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString());//from w ww. j av a 2s . com if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
From source file:Main.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString());//www. ja v a2 s . co m setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); setFont(list.getFont()); setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder); return this; }
From source file:ie.philb.testorderingsoapclient.ui.nav.products.ProductListCellRenderer.java
@Override public Component getListCellRendererComponent(JList<? extends Product> list, Product value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {//from ww w . j a v a2s . c o m if ((index % 2) == 0) { //setBackground(list.getBackground()); setBackground(new java.awt.Color(255, 255, 255)); setForeground(list.getForeground()); } else { setBackground(new java.awt.Color(245, 245, 245)); } } ListModel lm = list.getModel(); if (lm instanceof ProductListModel) { ProductListModel plm = (ProductListModel) lm; if (index < plm.getSize()) { Product p = plm.getElementAt(index); Money unitPrice = p.getUnitPrice(); lblTitle.setText(WordUtils.capitalize(p.getTitle())); lblCode.setText(p.getSkuCode()); lblUnitPrice.setText("" + unitPrice.getValue().toPlainString()); } else { lblTitle.setText(""); } return this; } return (Component) list.getCellRenderer(); }
From source file:net.sf.maltcms.chromaui.charts.renderer.XYPlotRendererListCellRenderer.java
@Override public Component getListCellRendererComponent(JList list, Object value, int i, boolean isSelected, boolean hasFocus) { //Get the selected index. (The index param isn't //always valid, so just use the value.) // int selectedIndex = ((Integer)value).intValue(); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {/* w ww . java 2 s . c o m*/ setBackground(list.getBackground()); setForeground(list.getForeground()); } if (value instanceof XYItemRenderer) { String className = ((XYItemRenderer) value).getClass().getSimpleName(); className = className.replaceFirst("XY", ""); className = className.replaceFirst("Renderer", ""); setText(className); } return this; }
From source file:Main.java
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { return new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Font font = (Font) value; String text = font.getFamily(); FontMetrics fm = g.getFontMetrics(font); g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground()); g.setFont(font);/*w w w .jav a 2 s . c o m*/ g.drawString(text, 0, fm.getAscent()); } public Dimension getPreferredSize() { Font font = (Font) value; String text = font.getFamily(); Graphics g = getGraphics(); FontMetrics fm = g.getFontMetrics(font); return new Dimension(fm.stringWidth(text), fm.getHeight()); } }; }
From source file:CheckBoxList.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof CheckBoxListEntry) { CheckBoxListEntry checkbox = (CheckBoxListEntry) value; checkbox.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); if (checkbox.isRed()) { checkbox.setForeground(Color.red); } else {/* w ww . j av a2 s . com*/ checkbox.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); } checkbox.setEnabled(isEnabled()); checkbox.setFont(getFont()); checkbox.setFocusPainted(false); checkbox.setBorderPainted(true); checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); return checkbox; } else { return super.getListCellRendererComponent(list, value.getClass().getName(), index, isSelected, cellHasFocus); } }
From source file:gg.msn.ui.panel.MainPanel.java
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { this.value = value; this.list = list; /*se il valore non nullo impossto il renderig altrimenti lo lascio nascosto, questo impedisce che lo spazio bianco selweziona sempre l'utlimo elemento*/ // log.debug("Render lement : " + value); if (isSelected) { setOpaque(true);/*from w ww .j av a2s . co m*/ setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setOpaque(false); setBackground(list.getBackground()); setForeground(list.getForeground()); } // <editor-fold defaultstate="collapsed" desc="Old Code"> /* try { //render per utenti Facebook if (ChatClientView.protocol.equals(ChatClientView.FACEBOOK_PROTOCOL)) { final FacebookUser user = (FacebookUser) value; setText(user.name); ImageIcon icon = user.portrait; //log.debug("icon [" + icon + "]"); ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING)); setFont(list.getFont()); setIcon(scaledIcon); //render per utenti Client } else { Client client = (Client) value; setText((client).getNick()); ImageIcon icon = null; try { new ImageIcon(client.getImage()); } catch (Exception e) { // log.debug("immgine non presente"); icon = ThemeManager.getTheme().get(ThemeManager.USER_ICON); } ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING)); setFont(list.getFont()); setIcon(scaledIcon); } } catch (Exception e) { log.warn(e); }*/// </editor-fold> return this; }
From source file:userinterface.graph.GraphOptionsPanel.java
/** Creates new form GraphOptionsPanel */ public GraphOptionsPanel(GUIPlugin plugin, JFrame parent, JPanel theModel) { this.plugin = plugin; this.parent = parent; this.theModel = theModel; /* TODO: Use generic container. */ ArrayList own = new ArrayList(); own.add(theModel);/*from w w w. j a v a2 s. c o m*/ graphPropertiesTable = new SettingTable(parent); graphPropertiesTable.setOwners(own); if (theModel instanceof Graph) { ((Graph) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Graph) theModel).getXAxisSettings(); yAxisSettings = ((Graph) theModel).getYAxisSettings(); zAxisSettings = null; displaySettings = ((Graph) theModel).getDisplaySettings(); } else if (theModel instanceof Histogram) { ((Histogram) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Histogram) theModel).getXAxisSettings(); yAxisSettings = ((Histogram) theModel).getYAxisSettings(); zAxisSettings = null; displaySettings = ((Histogram) theModel).getDisplaySettings(); } else if (theModel instanceof Graph3D) { ((Graph3D) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Graph3D) theModel).getxAxisSetting(); yAxisSettings = ((Graph3D) theModel).getyAxisSetting(); zAxisSettings = null; //zAxisSettings = ((Graph3D)theModel).getzAxisSetting(); displaySettings = ((Graph3D) theModel).getDisplaySettings(); } String[] axes = { "x-Axis", "y-Axis" }; axesList = new JList(axes); axesList.setSelectedIndex(0); axesList.addListSelectionListener(this); own = new ArrayList(); own.add(xAxisSettings); axisPropertiesTable = new SettingTable(parent); axisPropertiesTable.setOwners(own); if (theModel instanceof Graph) { ((AxisSettings) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettings) yAxisSettings).setDisplay(axisPropertiesTable); } else if (theModel instanceof Histogram) { ((AxisSettingsHistogram) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettingsHistogram) yAxisSettings).setDisplay(axisPropertiesTable); } else { ((AxisSettings3D) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettings3D) yAxisSettings).setDisplay(axisPropertiesTable); } own = new ArrayList(); own.add(displaySettings); displayPropertiesTable = new SettingTable(parent); displayPropertiesTable.setOwners(own); if (theModel instanceof ChartPanel) ((DisplaySettings) displaySettings).setDisplay(displayPropertiesTable); else if (theModel instanceof Graph3D) ((DisplaySettings3D) displaySettings).setDisplay(displayPropertiesTable); if (theModel instanceof Graph) { seriesList = new JList(((Graph) theModel).getGraphSeriesList()); } else if (theModel instanceof Histogram) { seriesList = new JList(((Histogram) theModel).getGraphSeriesList()); } else if (theModel instanceof Graph3D) { seriesList = new JList(((Graph3D) theModel).getGraphSeriesList()); } seriesList.addListSelectionListener(this); seriesList.setCellRenderer(new ListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = new JLabel((value == null) ? "undefined" : value.toString()); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); if (isSelected) { panel.setBackground(list.getSelectionBackground()); panel.setForeground(list.getSelectionForeground()); } else { panel.setBackground(list.getBackground()); panel.setForeground(list.getForeground()); } if (value instanceof SeriesSettings) { SeriesSettings graphSeries = (SeriesSettings) value; panel.add(graphSeries.getIcon()); } panel.add(label); return panel; } }); seriesPropertiesTable = new SettingTable(parent); /*seriesList = theModel.getSeriesList(); seriesList.addListSelectionListener(this); //seriesModel = new PropertyTableModel(); ArrayList ss = seriesList.getSelectedSeries(); //seriesModel.setOwners(ss); seriesProperties = new SettingTable(parent); seriesProperties.setOwners(ss);*/ initComponents(); //addSeries.setEnabled(ss.size() > 0); /*removeSeries.setEnabled(ss.size() > 0); moveUp.setEnabled(ss.size() > 0); moveDown.setEnabled(ss.size() > 0); viewData.setEnabled(ss.size() > 0);*/ }
From source file:filterviewplugin.FilterViewSettingsTab.java
public JPanel createSettingsPanel() { final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder(FormFactory.RELATED_GAP_COLSPEC.encode() + ',' + FormFactory.PREF_COLSPEC.encode() + ',' + FormFactory.RELATED_GAP_COLSPEC.encode() + ',' + FormFactory.PREF_COLSPEC.encode() + ", fill:default:grow"); final CellConstraints cc = new CellConstraints(); final JLabel label = new JLabel(mLocalizer.msg("daysToShow", "Days to show")); panelBuilder.addRow();/*from w w w . j a v a 2s. c o m*/ panelBuilder.add(label, cc.xy(2, panelBuilder.getRow())); final SpinnerNumberModel model = new SpinnerNumberModel(3, 1, 7, 1); mSpinner = new JSpinner(model); mSpinner.setValue(mSettings.getDays()); panelBuilder.add(mSpinner, cc.xy(4, panelBuilder.getRow())); panelBuilder.addParagraph(mLocalizer.msg("filters", "Filters to show")); mFilterList = new SelectableItemList(mSettings.getActiveFilterNames(), FilterViewSettings.getAvailableFilterNames()); mIcons.clear(); for (String filterName : FilterViewSettings.getAvailableFilterNames()) { mIcons.put(filterName, mSettings.getFilterIconName(mSettings.getFilter(filterName))); } mFilterList.addCenterRendererComponent(String.class, new SelectableItemRendererCenterComponentIf() { private DefaultListCellRenderer mRenderer = new DefaultListCellRenderer(); public void calculateSize(JList list, int index, JPanel contentPane) { } public JPanel createCenterPanel(JList list, Object value, int index, boolean isSelected, boolean isEnabled, JScrollPane parentScrollPane, int leftColumnWidth) { DefaultListCellRenderer label = (DefaultListCellRenderer) mRenderer .getListCellRendererComponent(list, value, index, isSelected, false); String filterName = value.toString(); String iconFileName = mIcons.get(filterName); Icon icon = null; if (!StringUtils.isEmpty(iconFileName)) { try { icon = FilterViewPlugin.getInstance().getIcon( FilterViewSettings.getIconDirectoryName() + File.separatorChar + iconFileName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } label.setIcon(icon); } String text = filterName; if (icon == null) { text += " (" + mLocalizer.msg("noIcon", "no icon") + ')'; } label.setText(text); label.setHorizontalAlignment(SwingConstants.LEADING); label.setVerticalAlignment(SwingConstants.CENTER); label.setOpaque(false); JPanel panel = new JPanel(new BorderLayout()); if (isSelected && isEnabled) { panel.setOpaque(true); panel.setForeground(list.getSelectionForeground()); panel.setBackground(list.getSelectionBackground()); } else { panel.setOpaque(false); panel.setForeground(list.getForeground()); panel.setBackground(list.getBackground()); } panel.add(label, BorderLayout.WEST); return panel; } }); panelBuilder.addGrowingRow(); panelBuilder.add(mFilterList, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); panelBuilder.addRow(); mFilterButton = new JButton(mLocalizer.msg("changeIcon", "Change icon")); mFilterButton.setEnabled(false); panelBuilder.add(mFilterButton, cc.xyw(2, panelBuilder.getRow(), 1)); mRemoveButton = new JButton(mLocalizer.msg("deleteIcon", "Remove icon")); mRemoveButton.setEnabled(false); panelBuilder.add(mRemoveButton, cc.xyw(4, panelBuilder.getRow(), 1)); mFilterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SelectableItem item = (SelectableItem) mFilterList.getSelectedValue(); String filterName = (String) item.getItem(); chooseIcon(filterName); } }); mFilterList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { mFilterButton.setEnabled(mFilterList.getSelectedValue() != null); mRemoveButton.setEnabled(mFilterButton.isEnabled()); } }); mRemoveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SelectableItem item = (SelectableItem) mFilterList.getSelectedValue(); String filterName = (String) item.getItem(); mIcons.put(filterName, ""); mFilterList.updateUI(); } }); return panelBuilder.getPanel(); }
From source file:org.domainmath.gui.MainFrame.java
public CompletionProvider createCompletionProvider() { DefaultCompletionProvider provider = new DefaultCompletionProvider(); JList l = new JList(); AutoCompleteListCellRenderer cellRender = new AutoCompleteListCellRenderer(l.getFont(), l.getBackground(), l.getForeground(), l.getSelectionBackground(), l.getSelectionForeground()); provider.setListCellRenderer(cellRender); OctaveM _m = new OctaveM(); List a = _m.getKey("DomainMath_OctaveAutoComplete.ini"); for (int i = 0; i < a.size(); i++) { provider.addCompletion(new BasicCompletion(provider, a.get(i).toString())); }/* ww w.j a v a 2 s . c om*/ return provider; }