本文整理汇总了Java中javax.swing.ListCellRenderer.getListCellRendererComponent方法的典型用法代码示例。如果您正苦于以下问题:Java ListCellRenderer.getListCellRendererComponent方法的具体用法?Java ListCellRenderer.getListCellRendererComponent怎么用?Java ListCellRenderer.getListCellRendererComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.ListCellRenderer
的用法示例。
在下文中一共展示了ListCellRenderer.getListCellRendererComponent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: paintCurrentValue
import javax.swing.ListCellRenderer; //导入方法依赖的package包/类
@Override
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
ListCellRenderer renderer = this.comboBox.getRenderer();
Component c;
if (hasFocus && !isPopupVisible(this.comboBox)) {
c = renderer.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, true, false);
} else {
c = renderer.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, false, false);
c.setBackground(UIManager.getColor("ComboBox.background"));
}
c.setFont(this.comboBox.getFont());
if (this.comboBox.isEnabled()) {
c.setForeground(this.comboBox.getForeground());
c.setBackground(this.comboBox.getBackground());
} else {
c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
}
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
if (Boolean.parseBoolean(String.valueOf(comboBox.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
c.setBackground(Colors.COMBOBOX_BACKGROUND_DARK);
} else {
c.setBackground(Colors.COMBOBOX_BACKGROUND);
}
this.currentValuePane.paintComponent(g, c, this.comboBox, bounds.x, bounds.y, bounds.width, bounds.height,
shouldValidate);
}
示例5: redispatchComponent
import javax.swing.ListCellRenderer; //导入方法依赖的package包/类
private boolean redispatchComponent(MouseEvent e) {
Point p = e.getPoint();
int index = list.locationToIndex(p);
if (index < 0 || index >= list.getModel().getSize()) {
return false;
}
ListCellRenderer renderer = list.getCellRenderer();
if (null == renderer) {
return false;
}
Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false);
if (null == renComponent) {
return false;
}
Rectangle rect = list.getCellBounds(index, index);
if (null == rect) {
return false;
}
renComponent.setBounds(0, 0, rect.width, rect.height);
renComponent.doLayout();
Point p3 = rect.getLocation();
Point p2 = new Point(p.x - p3.x, p.y - p3.y);
Component dispatchComponent =
SwingUtilities.getDeepestComponentAt(renComponent,
p2.x, p2.y);
if ( e.isPopupTrigger() &&
dispatchComponent instanceof LinkButton &&
!((LinkButton)dispatchComponent).isHandlingPopupEvents() )
{
return false;
}
if (dispatchComponent instanceof AbstractButton) {
if (!((AbstractButton) dispatchComponent).isEnabled()) {
return false;
}
Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent);
MouseEvent newEvent = new MouseEvent(dispatchComponent,
e.getID(),
e.getWhen(),
e.getModifiers(),
p4.x, p4.y,
e.getClickCount(),
e.isPopupTrigger(),
MouseEvent.NOBUTTON);
dispatchComponent.dispatchEvent(newEvent);
list.repaint(rect);
e.consume();
return true;
}
return false;
}
示例6: updateLayoutState
import javax.swing.ListCellRenderer; //导入方法依赖的package包/类
/**
* Recalculates the cell width and height of each cell in the list. This
* method is overridden to do a fast estimation if the completion list is
* too long, to improve performance for lists with huge amounts of
* completions.
*/
@Override
protected void updateLayoutState() {
ListModel model = list.getModel();
int itemCount = model.getSize();
// If the item count is small enough to run fast on practically all
// machines, go ahead and use the super implementation to determine
// the optimal cell sizes.
if (itemCount<ESTIMATION_THRESHOLD) {
super.updateLayoutState();
return;
}
// Otherwise, assume all cells are the same height as the first cell,
// and estimate the necessary width.
ListCellRenderer renderer = list.getCellRenderer();
cellWidth = list.getWidth();
if (list.getParent() instanceof JViewport) { // Always true for us
cellWidth = list.getParent().getWidth();
}
//System.out.println(cellWidth);
// We're getting a fixed cell height for all cells
cellHeights = null;
if (renderer!=null && itemCount>0) {
Object value = model.getElementAt(0);
java.awt.Component c = renderer.getListCellRendererComponent(list,
value, 0, false, false);
rendererPane.add(c);
Dimension cellSize = c.getPreferredSize();
cellHeight = cellSize.height;
cellWidth = Math.max(cellWidth, cellSize.width);
}
else {
cellHeight = 20;
}
}