/** * Return a component that has been configured to display the specified value. * * @param list The JList we're painting. * @param value The value returned by list.getModel().getElementAt(index). * @param index The cells index. * @param isSelected True if the specified cell was selected. * @param cellHasFocus True if the specified cell has the focus. * @return A component whose paint() method will render the specified value. * @todo Implement this javax.swing.ListCellRenderer method */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { HostItem hi = (HostItem) value; JLabel c = new JLabel(hi.name); if (isSelected && hi.eavesDroppingEnabled) { c.setBackground(Color.magenta); c.setForeground(list.getSelectionForeground()); } else if (!isSelected && hi.eavesDroppingEnabled) { c.setBackground(Color.red); c.setForeground(list.getForeground()); } else if (isSelected) { c.setBackground(list.getSelectionBackground()); c.setForeground(list.getSelectionForeground()); } else { c.setBackground(list.getBackground()); c.setForeground(list.getForeground()); } c.setEnabled(list.isEnabled()); c.setFont(list.getFont()); c.setOpaque(true); return c; }
public FilterField() { super(""); filterLabel = new JLabel("Filter"); filterLabel.setFont(Toolkit.getSansFont(14, Font.PLAIN)); filterLabel.setOpaque(false); setFont(Toolkit.getSansFont(14, Font.PLAIN)); searchIcon = Toolkit.getLibIconX("manager/search"); filterLabel.setIcon(searchIcon); // searchIcon = new // ImageIcon(java.awt.Toolkit.getDefaultToolkit().getImage("NSImage://NSComputerTemplate")); setOpaque(false); // setBorder(BorderFactory.createMatteBorder(0, 33, 0, 0, searchIcon)); GroupLayout fl = new GroupLayout(this); setLayout(fl); fl.setHorizontalGroup(fl.createSequentialGroup().addComponent(filterLabel)); fl.setVerticalGroup( fl.createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(filterLabel) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); filters = new ArrayList<String>(); addFocusListener( new FocusListener() { public void focusLost(FocusEvent focusEvent) { if (getText().isEmpty()) { // setBorder(BorderFactory.createMatteBorder(0, 33, 0, 0, searchIcon)); filterLabel.setVisible(true); } } public void focusGained(FocusEvent focusEvent) { // setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0)); filterLabel.setVisible(false); } }); getDocument() .addDocumentListener( new DocumentListener() { public void removeUpdate(DocumentEvent e) { applyFilter(); } public void insertUpdate(DocumentEvent e) { applyFilter(); } public void changedUpdate(DocumentEvent e) { applyFilter(); } }); }
protected void setLayout(final Editor editor, boolean activateErrorPanel, boolean isLoading) { if (progressBar == null) { progressBar = new JProgressBar(); progressBar.setVisible(false); createComponents(); buildErrorPanel(); loaderLabel = new JLabel(Toolkit.getLibIcon("manager/loader.gif")); loaderLabel.setOpaque(false); loaderLabel.setBackground(Color.WHITE); } int scrollBarWidth = contributionListPanel.scrollPane.getVerticalScrollBar().getPreferredSize().width; GroupLayout layout = new GroupLayout(this); setLayout(layout); // layout.setAutoCreateContainerGaps(true); // layout.setAutoCreateGaps(true); layout.setHorizontalGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addGroup( layout .createSequentialGroup() .addGap(ContributionManagerDialog.STATUS_WIDTH) .addComponent( filterField, ContributionManagerDialog.FILTER_WIDTH, ContributionManagerDialog.FILTER_WIDTH, ContributionManagerDialog.FILTER_WIDTH) // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent( categoryChooser, ContributionManagerDialog.AUTHOR_WIDTH, ContributionManagerDialog.AUTHOR_WIDTH, ContributionManagerDialog.AUTHOR_WIDTH) .addGap(scrollBarWidth)) .addComponent(loaderLabel) .addComponent(contributionListPanel) .addComponent(errorPanel) .addComponent(statusPanel)); layout.setVerticalGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(categoryChooser) .addComponent(filterField)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(loaderLabel) .addComponent(contributionListPanel)) .addComponent(errorPanel) .addComponent( statusPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); layout.linkSize(SwingConstants.VERTICAL, categoryChooser, filterField); // these will occupy space even if not visible layout.setHonorsVisibility(contributionListPanel, false); layout.setHonorsVisibility(categoryChooser, false); setBackground(Color.WHITE); setBorder(null); }