本文整理汇总了Java中javax.swing.ListCellRenderer类的典型用法代码示例。如果您正苦于以下问题:Java ListCellRenderer类的具体用法?Java ListCellRenderer怎么用?Java ListCellRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListCellRenderer类属于javax.swing包,在下文中一共展示了ListCellRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSelectorsRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
private ListCellRenderer createSelectorsRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null) {
SelectorItemRenderer selectorModelItemRenderer = getSelectorModelItemRenderer();
selectorModelItemRenderer.setItem((SelectorItem) value, isSelected);
return selectorModelItemRenderer;
// setText(item.getDisplayName());
}
return c;
}
};
}
示例2: createAtRulesRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
/**
* Creates a renderer for the at-rules combobox dropdown.
*/
private ListCellRenderer createAtRulesRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
setText(Bundle.none_item());
} else if(value instanceof AtRuleItem) {
setText(((AtRuleItem) value).getDisplayName());
} else if(value instanceof String) {
setText((String)value);
}
return c;
}
};
}
示例3: getListCellRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
@Override
@NonNull
public ListCellRenderer getListCellRenderer(
@NonNull final JList list,
@NonNull final Document nameDocument,
@NonNull final ButtonModel caseSensitive,
@NonNull final ButtonModel colorPrefered) {
Parameters.notNull("list", list); //NOI18N
Parameters.notNull("nameDocument", nameDocument); //NOI18N
Parameters.notNull("caseSensitive", caseSensitive); //NOI18N
return ItemRenderer.Builder.create(
list,
caseSensitive,
new FileDescriptorConvertor(nameDocument)).
setCamelCaseSeparator(CAMEL_CASE_SEPARATOR).
setColorPreferedProject(colorPrefered).
build();
}
示例4: createStyleSheetsRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
private ListCellRenderer createStyleSheetsRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
setText("<html>" + Bundle.none_item());
} else {
FileObject file = (FileObject) value;
FileObject webRoot = ProjectWebRootQuery.getWebRoot(file);
String file2string;
if (webRoot != null) {
file2string = FileUtil.getRelativePath(webRoot, file);
} else {
file2string = FileUtil.getFileDisplayName(file);
}
setText(file2string);
}
return c;
}
};
}
示例5: FolderBasedOptionPanel
import javax.swing.ListCellRenderer; //导入依赖的package包/类
/** Creates new form FolderBasedOptionPanel */
FolderBasedOptionPanel(FolderBasedController controller, Document filterDocument, boolean allowFiltering) {
this.controller = controller;
initComponents();
filter.setDocument(filterDocument);
if (!allowFiltering) {
filter.setVisible(false);
filterLabel.setVisible(false);
}
ListCellRenderer renderer = new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof String)
value = EditorSettings.getDefault().getLanguageName((String)value);
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
};
languageCombo.setRenderer(renderer);
languageCombo.addActionListener(this);
update();
}
示例6: getRendererComponent
import javax.swing.ListCellRenderer; //导入依赖的package包/类
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;
}
return rendererComponent;
}
示例7: getListCellRendererComponent
import javax.swing.ListCellRenderer; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean selected, boolean hasFocus) {
Completion c = (Completion)value;
CompletionProvider p = c.getProvider();
ListCellRenderer r = p.getListCellRenderer();
if (r!=null) {
return r.getListCellRendererComponent(list, value, index, selected,
hasFocus);
}
if (fallback==null) {
return super.getListCellRendererComponent(list, value, index,
selected, hasFocus);
}
return fallback.getListCellRendererComponent(list, value, index,
selected, hasFocus);
}
示例8: createRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
private ListCellRenderer createRenderer()
{
return new DefaultListCellRenderer()
{
private final Component SEPARATOR = new SeparatorComponent();
public Component getListCellRendererComponent( JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus)
{
if ( value instanceof ComboItem )
{
value = ((ComboItem)value).getDelegate();
}
if ( value == null )
{
return SEPARATOR;
}
return super.getListCellRendererComponent( list, value, index,
isSelected, cellHasFocus );
}
};
}
示例9: getBestPopupSizeForRowCount
import javax.swing.ListCellRenderer; //导入依赖的package包/类
protected Dimension getBestPopupSizeForRowCount(final int maxRowCount) {
final int currentElementCount = comboBox.getModel().getSize();
final int rowCount = Math.min(maxRowCount, currentElementCount);
final Dimension popupSize = new Dimension();
final ListCellRenderer<Object> renderer = list.getCellRenderer();
for (int i = 0; i < rowCount; i++) {
final Object value = list.getModel().getElementAt(i);
final Component c = renderer.getListCellRendererComponent(list, value, i, false, false);
final Dimension prefSize = c.getPreferredSize();
popupSize.height += prefSize.height;
popupSize.width = Math.max(prefSize.width, popupSize.width);
}
popupSize.width += 10;
return popupSize;
}
示例10: getCellRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
public ListCellRenderer getCellRenderer() {
return new DefaultListCellRenderer() {
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
{
JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String s = value.toString();
label.setText(s);
//Note currentNote = CurrentProject.getNoteList().getActiveNote();
Note currentNote = CurrentNote.get();
if (currentNote != null) {
if (getNote(index).getId().equals(currentNote.getId()))
label.setFont(label.getFont().deriveFont(Font.BOLD));
}
if (getNote(index).isMarked())
label.setIcon(bookmarkIcon);
//setIcon();
/*if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
setOpaque(true);*/
label.setToolTipText(s);
return label;
}
};
}
示例11: createAtRulesRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
private ListCellRenderer createAtRulesRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
setText(Bundle.EditRulesPanel_none_item());
} else {
setText(((MediaItem) value).getDisplayName());
}
return c;
}
};
}
示例12: createSelectorsRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
/**
* Creates a renderer for the selectors combobox dropdown.
*/
private ListCellRenderer createSelectorsRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null) {
if(value instanceof SelectorItem) {
SelectorItem selectorItem = (SelectorItem) value;
if (selectorItem == NO_CLASS || selectorItem == NO_ID) {
setText(Bundle.none_item());
return c;
} else {
SelectorItemRenderer selectorModelItemRenderer = getSelectorModelItemRenderer();
boolean originalElement = false;
switch (selectorItem.getType()) {
case SelectorItem.CLASS_TYPE:
originalElement = selectorItem.getItemName().equals(getSelectedElementClassName());
break;
case SelectorItem.ID_TYPE:
originalElement = selectorItem.getItemName().equals(getSelectedElementIdName());
break;
}
selectorModelItemRenderer.setItem(selectorItem, isSelected, originalElement);
return selectorModelItemRenderer;
}
}
} else if(value instanceof String) {
setText((String)value);
}
return c;
}
};
}
示例13: createStylesheetsRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
/**
* Creates a renderer for the stylesheets combobox dropdown.
*/
private ListCellRenderer createStylesheetsRenderer() {
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
//empty model
return c;
}
if(value instanceof FileObject) {
FileObject file = (FileObject) value;
if(webRoot == null) {
setText(file.getNameExt());
} else {
String relativePath = FileUtil.getRelativePath(webRoot, file);
if(relativePath != null) {
setText(relativePath);
} else {
//should not happen
setText(file.getNameExt());
}
}
} else if(value instanceof String) {
setText((String)value);
}
return c;
}
};
}
示例14: showJList
import javax.swing.ListCellRenderer; //导入依赖的package包/类
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();
}
}
}
示例15: getItemRenderer
import javax.swing.ListCellRenderer; //导入依赖的package包/类
private static ListCellRenderer getItemRenderer () {
ListCellRenderer renderer = rendererRef == null ? null : rendererRef.get ();
if (renderer == null) {
renderer = new ItemRenderer ();
rendererRef = new WeakReference<ListCellRenderer>( renderer );
}
return renderer;
}