本文整理汇总了Java中javax.swing.JList.getBackground方法的典型用法代码示例。如果您正苦于以下问题:Java JList.getBackground方法的具体用法?Java JList.getBackground怎么用?Java JList.getBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JList
的用法示例。
在下文中一共展示了JList.getBackground方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getListCellRendererComponent
import javax.swing.JList; //导入方法依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (!(value instanceof TreeListNode)) {
//shoudln't happen
return new JLabel();
}
TreeListNode node = (TreeListNode) value;
int rowHeight = list.getFixedCellHeight();
int rowWidth = list.getVisibleRect().width;
int dropIndex = -1;
DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null && !dropLocation.isInsert()) {
dropIndex = dropLocation.getIndex();
}
boolean isDropTarget = dropIndex == index;
isSelected = isSelected || isDropTarget;
Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();
return node.getRenderer(foreground, background, isSelected, cellHasFocus, rowHeight, rowWidth);
}
示例2: getListCellRendererComponent
import javax.swing.JList; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
if (!(value instanceof ListNode)) {
//shoudln't happen
return new JLabel();
}
if( list instanceof SelectionList ) {
isSelected |= index == ((SelectionList)list).getMouseOverRow();
}
ListNode node = (ListNode) value;
int rowHeight = list.getFixedCellHeight();
int rowWidth = list.getWidth();
JScrollPane scroll = ( JScrollPane ) SwingUtilities.getAncestorOfClass( JScrollPane.class, list);
if( null != scroll )
rowWidth = scroll.getViewport().getWidth();
Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();
return node.getListRenderer(foreground, background, isSelected, cellHasFocus, rowHeight, rowWidth);
}
示例3: configure
import javax.swing.JList; //导入方法依赖的package包/类
/** Configures a list cell renderer and sets up sizing and the
* backing image from it */
public boolean configure (Object nd, JScrollPane tv, JList list, int row) {
boolean sameVn = setLastRendereredObject(nd);
boolean sameComp = setLastRenderedScrollPane (tv);
Component renderer = null;
bg = list.getBackground();
boolean sel = list.isSelectionEmpty() ? false :
list.getSelectionModel().isSelectedIndex(row);
renderer = list.getCellRenderer().getListCellRendererComponent(list, nd, row, sel, false);
if (renderer != null) {
setComponent (renderer, list);
}
return true;
}
示例4: Renderer
import javax.swing.JList; //导入方法依赖的package包/类
public Renderer(JList list) {
setFont(list.getFont());
fgColor = list.getForeground();
bgColor = list.getBackground();
bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
bgSelectionColor = list.getSelectionBackground();
fgSelectionColor = list.getSelectionForeground();
}
示例5: Renderer
import javax.swing.JList; //导入方法依赖的package包/类
public Renderer( JList list ) {
setFont( list.getFont() );
fgColor = list.getForeground();
bgColor = list.getBackground();
bgColorDarker = new Color(
Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)
);
bgSelectionColor = list.getSelectionBackground();
fgSelectionColor = list.getSelectionForeground();
}
示例6: getListCellRendererComponent
import javax.swing.JList; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(JList<? extends AuthenticationCheckboxListItem> list, AuthenticationCheckboxListItem value,
int index, boolean isSelected, boolean cellHasFocus) {
final Color bc;
final Color fc;
if (isSelected) {
bc = UIManager.getColor("List.selectionBackground"); //NOI18N
fc = UIManager.getColor("List.selectionForeground"); //NOI18N
} else {
bc = list.getBackground();
fc = list.getForeground();
}
setBackground(bc); // NOI18N
setForeground(fc); // NOI18N
label.setBackground(bc);
label.setForeground(fc);
label.setText(value.getDisplayName());
label.setFont(list.getFont());
check.setSelected(value.isSelected());
check.setBackground(bc);
check.setForeground(fc);
check.setEnabled(list.isEnabled());
Border border;
if (cellHasFocus) {
border = focusBorder;
} else {
border = noFocusBorder;
}
setBorder(border);
return this;
}
示例7: getListCellRendererComponent
import javax.swing.JList; //导入方法依赖的package包/类
/**
* Returns the renderer.
*
* @param list The list of choices being rendered.
* @param value The {@link Completion} being rendered.
* @param index The index into <code>list</code> being rendered.
* @param selected Whether the item is selected.
* @param hasFocus Whether the item has focus.
*/
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean selected, boolean hasFocus) {
super.getListCellRendererComponent(list,value,index,selected,hasFocus);
if (font!=null) {
setFont(font); // Overrides super's setFont(list.getFont()).
}
this.selected = selected;
this.realBG = altBG!=null && (index&1)==1 ? altBG : list.getBackground();
Completion c = (Completion)value;
setIcon(c.getIcon());
if (c instanceof FunctionCompletion) {
FunctionCompletion fc = (FunctionCompletion)value;
prepareForFunctionCompletion(list, fc, index, selected, hasFocus);
}
else if (c instanceof VariableCompletion) {
VariableCompletion vc = (VariableCompletion)value;
prepareForVariableCompletion(list, vc, index, selected, hasFocus);
}
else if (c instanceof TemplateCompletion) {
TemplateCompletion tc = (TemplateCompletion)value;
prepareForTemplateCompletion(list, tc, index, selected, hasFocus);
}
else if (c instanceof MarkupTagCompletion) {
MarkupTagCompletion mtc = (MarkupTagCompletion)value;
prepareForMarkupTagCompletion(list, mtc, index, selected, hasFocus);
}
else {
prepareForOtherCompletion(list, c, index, selected, hasFocus);
}
// A delegate renderer might do its own alternate row striping
// (Substance does).
if (delegate!=null) {
delegate.getListCellRendererComponent(list, getText(), index,
selected, hasFocus);
delegate.setFont(getFont());
delegate.setIcon(getIcon());
return delegate;
}
if (!selected && (index&1)==1 && altBG!=null) {
setBackground(altBG);
}
return this;
}