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

The following examples show how to use javax.swing.JList#setCellRenderer() . 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: JSList.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 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
Source File: RemotePrinterStatusRefresh.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private JPanel createListPanel(final ServiceItemListModel model,
                               final String title,
                               final char mnemonic) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JList<ServiceItem> list = new JList<>(model);
    list.setCellRenderer(new ServiceItemListRenderer());

    JLabel label = new JLabel(title);
    label.setLabelFor(list);
    label.setDisplayedMnemonic(mnemonic);
    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
    labelPanel.add(label, BorderLayout.EAST);
    labelPanel.add(Box.createHorizontalGlue());

    panel.add(labelPanel);
    panel.add(new JScrollPane(list));
    return panel;
}
 
Example 3
Source File: RemotePrinterStatusRefresh.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private JPanel createListPanel(final ServiceItemListModel model,
                               final String title,
                               final char mnemonic) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JList<ServiceItem> list = new JList<>(model);
    list.setCellRenderer(new ServiceItemListRenderer());

    JLabel label = new JLabel(title);
    label.setLabelFor(list);
    label.setDisplayedMnemonic(mnemonic);
    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
    labelPanel.add(label, BorderLayout.EAST);
    labelPanel.add(Box.createHorizontalGlue());

    panel.add(labelPanel);
    panel.add(new JScrollPane(list));
    return panel;
}
 
Example 4
Source File: MissedCalls.java    From Spark with Apache License 2.0 5 votes vote down vote up
public MissedCalls() {
    model = new DefaultListModel();
    list = new JList(model);
    gui = getMissedCallPanel();


    list.setCellRenderer(new MissedCallRenderer());
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2) {
                placeCall((MissedCall)list.getSelectedValue());
            }
        }
    });

    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }

            int selectedIndex = list.getSelectedIndex();
            boolean enabled = selectedIndex != -1;
            callBackButton.setEnabled(enabled);
            deleteButton.setEnabled(enabled);
        }
    });
}
 
Example 5
Source File: FilesModifiedConfirmation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JList createFilesList(SaveCookie[] saveCookies) {
    JList filesList = new JList(
                listModel = new ArrayListModel<SaveCookie>(saveCookies));
    filesList.setVisibleRowCount(8);
    filesList.setPrototypeCellValue(PROTOTYPE_LIST_CELL_VALUE);
    filesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    filesList.addListSelectionListener(listener);
    filesList.setCellRenderer(new ListCellRenderer());

    return filesList;
}
 
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: ToolSelectorPanel.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Creates a new ToolSelectorPanel.
 * 
 * @param parent The ToolPanel, for communication purposes.
 */
public ToolSelectorPanel(ToolPanel parent, ToolModule toolModule) {
	super(new GridLayout(1, 2));
	this.toolPanel = parent;
	this.toolModule = toolModule;
	
       List<ToolCategory> toolCategories;
       toolCategories = Collections.list(Collections.enumeration(toolModule.getVisibleCategories()));
       
	categoryList = new JList();
	categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	categoryList.addListSelectionListener(this);
	categoryList.setCellRenderer(new CategoryListRenderer());
	categoryList.getInsets().right = 1;
	categoryList.setName("categoryList");
	categoryList.setListData(toolCategories.toArray());
	
	
	
	toolList = new JList();
	toolList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	toolList.addListSelectionListener(this);
	toolList.setCellRenderer(new FontSizeFriendlyListRenderer());
	toolList.addMouseListener(new MouseClickListener());
	toolList.getInsets().right = 1;
	toolList.setName("toolList");
	
	JScrollPane categoryListScroller = new JScrollPane(categoryList);		
	JScrollPane toolListScroller = new JScrollPane(toolList);
	
	//Remove useless borders
	categoryListScroller.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1,
	        VisualConstants.TOOL_LIST_BORDER_COLOR));
	toolListScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
	
	this.add(categoryListScroller);
	this.add(toolListScroller);
}
 
Example 8
Source File: DiplomacyView.java    From Open-Realms-of-Stars with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create Planet List from planet array
 * @param planets Which are used for creating planet List
 * @return JList full of planets
 */
private JList<Planet> createPlanetList(final Planet[] planets) {
  JList<Planet> planetList = new JList<>(planets);
  planetList.setCellRenderer(new PlanetListRenderer());
  planetList.setBackground(Color.BLACK);
  planetList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  return planetList;
}
 
Example 9
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 10
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 11
Source File: ConnectionPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void initPanel()
{
  setLayout(new BorderLayout());

  final JList dataSourceList = new JList(dialogModel.getConnections());
  dataSourceList.setCellRenderer(new DataSourceDefinitionListCellRenderer());
  dataSourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  dataSourceList.addListSelectionListener(new DataSourceDefinitionListSelectionListener(dataSourceList));
  dataSourceList.setVisibleRowCount(10);

  final SelectionConnectionUpdateHandler theSelectedConnectionAction = new SelectionConnectionUpdateHandler(
      dataSourceList);
  dialogModel.addPropertyChangeListener(theSelectedConnectionAction);

  final EditDataSourceAction editDataSourceAction = new EditDataSourceAction(dataSourceList);
  dialogModel.addPropertyChangeListener(editDataSourceAction);

  final RemoveDataSourceAction removeDataSourceAction = new RemoveDataSourceAction(dataSourceList);
  dialogModel.addPropertyChangeListener(removeDataSourceAction);

  final JPanel connectionButtonPanel = new JPanel();
  connectionButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  if (isSecurityConfigurationAvailable())
  {
    connectionButtonPanel.add(new JButton(createEditSecurityAction()));
    connectionButtonPanel.add(Box.createHorizontalStrut(40));
  }
  connectionButtonPanel.add(new BorderlessButton(editDataSourceAction));
  connectionButtonPanel.add(new BorderlessButton(new AddDataSourceAction(dataSourceList)));
  connectionButtonPanel.add(new BorderlessButton(removeDataSourceAction));

  final JPanel connectionButtonPanelWrapper = new JPanel(new BorderLayout());
  connectionButtonPanelWrapper.add(new JLabel(bundleSupport.getString("ConnectionPanel.Connections")), BorderLayout.CENTER);
  connectionButtonPanelWrapper.add(connectionButtonPanel, BorderLayout.EAST);

  add(BorderLayout.NORTH, connectionButtonPanelWrapper);
  add(BorderLayout.CENTER, new JScrollPane(dataSourceList));
}
 
Example 12
Source File: CheckBoxListDecorator.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public CheckBoxListDecorator(JList<T> list) {
	this.list = list;

	list.setCellRenderer(new CheckBoxListCellRenderer<T>());
	list.addMouseListener(this); 
	list.addPropertyChangeListener(this);
	list.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED); 

	checkBoxSelectionModel = new DefaultListSelectionModel();
	checkBoxSelectionModel.addListSelectionListener(this);

	enabled = new HashMap<Integer, Boolean>();
	width = new JCheckBox().getPreferredSize().width;
}
 
Example 13
Source File: DDChangesPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Initializes the Form */
public DDChangesPanel (String caption, final JButton processButton) {
    setLayout (new java.awt.BorderLayout (0, 12));
    setBorder (new EmptyBorder (12, 12, 11, 0));
    
    JTextArea text = new JTextArea ();
    text.setEnabled (false);
    text.setEditable (false);
    text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); // NOI18N
    text.setBackground (UIManager.getColor ("Label.background")); // NOI18N
    text.setLineWrap (true);
    text.setWrapStyleWord (true);
    text.setText (caption);
    add (text, "North"); // NOI18N
    
    changesPanel = new JPanel ();
    changesPanel.setLayout (new java.awt.BorderLayout (5, 5));
    
    JLabel changesLabel = new JLabel ();
    changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList"));
    changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc"));  // NOI18N
    changesPanel.add (changesLabel, "North"); // NOI18N
    
    jScrollPane1 = new JScrollPane ();
    
    listModel = new DefaultListModel ();
    
    changesList = new JList (listModel);
    changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList"));
    changesList.setCellRenderer (new ChangesListCellRenderer ());
    changesList.addListSelectionListener (new ListSelectionListener () {
        public void valueChanged (ListSelectionEvent e) {
            processButton.setEnabled (!changesList.isSelectionEmpty ());
        }
    });
    changesLabel.setLabelFor (changesList);
    changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0));
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc"));
    
    jScrollPane1.setViewportView (changesList);
    
    changesPanel.add (jScrollPane1, "Center"); // NOI18N
    
    add (changesPanel, "Center"); // NOI18N
}
 
Example 14
Source File: CheckListView.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected JList createList() {
    JList tmpList = super.createList();
    tmpList.setCellRenderer(new CheckRenderer(tmpList));
    return tmpList;
}
 
Example 15
Source File: SourceProductList.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private JList<Object> createInputPathsList(InputListModel inputListModel) {
    JList<Object> list = new JList<>(inputListModel);
    list.setCellRenderer(new SourceProductListRenderer());
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    return list;
}
 
Example 16
Source File: CheckListView.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected JList createList() {
    JList tmpList = super.createList();
    tmpList.setCellRenderer(new CheckRenderer(tmpList));
    return tmpList;
}
 
Example 17
Source File: PerformanceVectorViewer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public PerformanceVectorViewer(final PerformanceVector performanceVector, final IOContainer container) {
	setLayout(new BorderLayout());

	// all criteria
	final CardLayout cardLayout = new CardLayout();
	final JPanel mainPanel = new JPanel(cardLayout);
	add(mainPanel, BorderLayout.CENTER);
	List<String> criteriaNameList = new LinkedList<>();
	for (int i = 0; i < performanceVector.getSize(); i++) {
		PerformanceCriterion criterion = performanceVector.getCriterion(i);
		criteriaNameList.add(criterion.getName());
		JPanel component = ResultDisplayTools.createVisualizationComponent(criterion, container,
				"Performance Criterion", false);
		JScrollPane criterionPane = new ExtendedJScrollPane(component);
		criterionPane.setBorder(null);
		criterionPane.setBackground(Colors.WHITE);
		mainPanel.add(criterionPane, criterion.getName());
	}
	if (criteriaNameList.isEmpty()) {
		remove(mainPanel);
		add(new ResourceLabel("result_view.no_criterions"));
		return;
	}
	String[] criteriaNames = new String[criteriaNameList.size()];
	criteriaNameList.toArray(criteriaNames);

	// selection list
	final JList<String> criteriaList = new MenuShortcutJList<String>(criteriaNames, false) {

		private static final long serialVersionUID = 3031125186920370793L;

		@Override
		public Dimension getPreferredSize() {
			Dimension dim = super.getPreferredSize();
			dim.width = Math.max(150, dim.width);
			return dim;
		}
	};
	criteriaList.setCellRenderer(new CriterionListCellRenderer());
	criteriaList.setOpaque(false);

	criteriaList.setBorder(BorderFactory.createTitledBorder("Criterion"));
	criteriaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	criteriaList.addListSelectionListener(new ListSelectionListener() {

		@Override
		public void valueChanged(ListSelectionEvent e) {
			String selected = criteriaList.getSelectedValue();
			cardLayout.show(mainPanel, selected);
		}
	});

	JScrollPane listScrollPane = new ExtendedJScrollPane(criteriaList);
	listScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 2));
	add(listScrollPane, BorderLayout.WEST);

	// select first criterion
	criteriaList.setSelectedIndices(new int[] { 0 });
}
 
Example 18
Source File: CheckListView.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected JList createList() {
    JList tmpList = super.createList();
    tmpList.setCellRenderer(new CheckRenderer(tmpList));
    return tmpList;
}
 
Example 19
Source File: ProfilerOptionsContainer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    categoriesModel = new CategoriesListModel();
    categoriesSelection = new CategoriesSelectionModel();
    
    scrollIncrement = new JCheckBox("XXX").getPreferredSize().height; // NOI18N
    
    JList<ProfilerOptionsPanel> categoriesList = new JList<ProfilerOptionsPanel>(categoriesModel) {
        public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            dim.width = Math.max(dim.width + 20, 140);
            return dim;
        }
    };
    categoriesList.setVisibleRowCount(0);
    categoriesList.setSelectionModel(categoriesSelection);
    categoriesList.setCellRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            String panelName = " " + ((ProfilerOptionsPanel)value).getDisplayName() + " "; // NOI18N
            return super.getListCellRendererComponent(list, panelName, index, isSelected, cellHasFocus);
        }
    });
    
    JScrollPane categoriesScroll = new JScrollPane(categoriesList);
    
    JLabel categoriesLabel = new JLabel();
    categoriesLabel.setHorizontalAlignment(JLabel.LEADING);
    Mnemonics.setLocalizedText(categoriesLabel, Bundle.ProfilerOptionsContainer_Categories());
    categoriesLabel.setLabelFor(categoriesList);
    int labelOffset = 6;
    
    JPanel categoriesPanel = new JPanel(new BorderLayout(0, labelOffset));
    categoriesPanel.add(categoriesLabel, BorderLayout.NORTH);
    categoriesPanel.add(categoriesScroll, BorderLayout.CENTER);
    
    content = new JPanel(new BorderLayout());
    content.setBorder(BorderFactory.createEmptyBorder(categoriesLabel.getPreferredSize().height + labelOffset, 11, 0, 0));
    content.setMinimumSize(new Dimension(0, 0));
    content.setPreferredSize(new Dimension(0, 0));
    
    setLayout(new BorderLayout());
    add(categoriesPanel, BorderLayout.WEST);
    add(content, BorderLayout.CENTER);
}
 
Example 20
Source File: ReadLogsWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 4 votes vote down vote up
private JList<String> logFilesList() {
	
	
	file = new File(System.getProperty("user.dir") + File.separator + "Logging Store/");
	
	final JFileChooser fileChooser = new JFileChooser();
	fileChooser.setCurrentDirectory(file);
	fileChooser.setMultiSelectionEnabled(true);

	final DefaultListModel<String> model = new DefaultListModel<String>();
	
	final JList<String> list = new JList<String>(model);
	list.setPreferredSize(new Dimension(85, 480));
	list.setFont(new Font("Dialog", Font.PLAIN, 12));
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.setSelectedIndex(0);
	list.setFixedCellHeight(18);
	list.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			if (e.getClickCount() == 2) {
				selectedItem = list.getSelectedValue();
				getSelectedFileName();
			}
		}
	});
	
	list.setCellRenderer(new LogRecordsListRenderer());

	File[] selectedFiles = fileChooser.getCurrentDirectory().listFiles();

	for (File f : selectedFiles) {
		if (f.getName().indexOf(".log") != -1) {
			model.addElement(f.getName());
		}else {
			continue;
		}
	}
	if(model.isEmpty()) {
		model.addElement("List is empty!");
	}
	
	return list;
}