本文整理汇总了Java中sun.swing.DefaultLookup.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultLookup.getColor方法的具体用法?Java DefaultLookup.getColor怎么用?Java DefaultLookup.getColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.swing.DefaultLookup
的用法示例。
在下文中一共展示了DefaultLookup.getColor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableCellRendererComponent
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color fg = null;
Color bg = null;
JTable.DropLocation dropLocation = table.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsertRow()
&& !dropLocation.isInsertColumn()
&& dropLocation.getRow() == row
&& dropLocation.getColumn() == column) {
fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");
isSelected = true;
}
if (isSelected) {
setBackground(DefaultLookup.getColor(this, ui, "Table.dropCellBackground"));
} else {
setBackground( DefaultLookup.getColor(this, ui, "Table.alternateRowColor"));
}
MapRule rule=(MapRule)value;
update(rule,table,row);
return this;
}
示例2: paintDropLine
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
private void paintDropLine(Graphics g) {
JList.DropLocation loc = list.getDropLocation();
if (loc == null || !loc.isInsert()) {
return;
}
Color c = DefaultLookup.getColor(list, this, "List.dropLineColor", null);
if (c != null) {
g.setColor(c);
Rectangle rect = getDropLineRect(loc);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
}
示例3: getTableCellRendererComponent
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Icon sortIcon = null;
boolean isPaintingForPrint = false;
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
Color fgColor = null;
Color bgColor = null;
if (hasFocus) {
fgColor = DefaultLookup.getColor(this, ui, "TableHeader.focusCellForeground");
bgColor = DefaultLookup.getColor(this, ui, "TableHeader.focusCellBackground");
}
if (fgColor == null) {
fgColor = header.getForeground();
}
if (bgColor == null) {
bgColor = header.getBackground();
}
setForeground(fgColor);
setBackground(bgColor);
setFont(header.getFont());
isPaintingForPrint = header.isPaintingForPrint();
}
if (!isPaintingForPrint && table.getRowSorter() != null) {
if (!horizontalTextPositionSet) {
// There is a row sorter, and the developer hasn't
// set a text position, change to leading.
setHorizontalTextPosition(JLabel.LEADING);
}
SortOrder sortOrder = getColumnSortOrder(table, column);
if (sortOrder != null) {
switch(sortOrder) {
case ASCENDING:
sortIcon = DefaultLookup.getIcon(
this, ui, "Table.ascendingSortIcon");
break;
case DESCENDING:
sortIcon = DefaultLookup.getIcon(
this, ui, "Table.descendingSortIcon");
break;
case UNSORTED:
sortIcon = DefaultLookup.getIcon(
this, ui, "Table.naturalSortIcon");
break;
}
}
}
}
setText(value == null ? "" : value.toString());
setIcon(sortIcon);
sortArrow = sortIcon;
Border border = null;
if (hasFocus) {
border = DefaultLookup.getBorder(this, ui, "TableHeader.focusCellBorder");
}
if (border == null) {
border = DefaultLookup.getBorder(this, ui, "TableHeader.cellBorder");
}
setBorder(border);
return this;
}
示例4: getTreeCellRendererComponent
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
/**
* Configures the renderer based on the passed in components.
* The value is set from messaging the tree with
* <code>convertValueToText</code>, which ultimately invokes
* <code>toString</code> on <code>value</code>.
* The foreground color is set based on the selection and the icon
* is set based on the <code>leaf</code> and <code>expanded</code>
* parameters.
*/
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
String stringValue = tree.convertValueToText(value, sel,
expanded, leaf, row, hasFocus);
this.tree = tree;
this.hasFocus = hasFocus;
setText(stringValue);
Color fg = null;
isDropCell = false;
JTree.DropLocation dropLocation = tree.getDropLocation();
if (dropLocation != null
&& dropLocation.getChildIndex() == -1
&& tree.getRowForPath(dropLocation.getPath()) == row) {
Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
if (col != null) {
fg = col;
} else {
fg = getTextSelectionColor();
}
isDropCell = true;
} else if (sel) {
fg = getTextSelectionColor();
} else {
fg = getTextNonSelectionColor();
}
setForeground(fg);
Icon icon = null;
if (leaf) {
icon = getLeafIcon();
} else if (expanded) {
icon = getOpenIcon();
} else {
icon = getClosedIcon();
}
if (!tree.isEnabled()) {
setEnabled(false);
LookAndFeel laf = UIManager.getLookAndFeel();
Icon disabledIcon = laf.getDisabledIcon(tree, icon);
if (disabledIcon != null) icon = disabledIcon;
setDisabledIcon(icon);
} else {
setEnabled(true);
setIcon(icon);
}
setComponentOrientation(tree.getComponentOrientation());
selected = sel;
return this;
}
示例5: paint
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
/**
* Paints the value. The background is filled based on selected.
*/
public void paint(Graphics g) {
Color bColor;
if (isDropCell) {
bColor = DefaultLookup.getColor(this, ui, "Tree.dropCellBackground");
if (bColor == null) {
bColor = getBackgroundSelectionColor();
}
} else if (selected) {
bColor = getBackgroundSelectionColor();
} else {
bColor = getBackgroundNonSelectionColor();
if (bColor == null) {
bColor = getBackground();
}
}
int imageOffset = -1;
if (bColor != null && fillBackground) {
imageOffset = getLabelStart();
g.setColor(bColor);
if(getComponentOrientation().isLeftToRight()) {
g.fillRect(imageOffset, 0, getWidth() - imageOffset,
getHeight());
} else {
g.fillRect(0, 0, getWidth() - imageOffset,
getHeight());
}
}
if (hasFocus) {
if (drawsFocusBorderAroundIcon) {
imageOffset = 0;
}
else if (imageOffset == -1) {
imageOffset = getLabelStart();
}
if(getComponentOrientation().isLeftToRight()) {
paintFocus(g, imageOffset, 0, getWidth() - imageOffset,
getHeight(), bColor);
} else {
paintFocus(g, 0, 0, getWidth() - imageOffset, getHeight(), bColor);
}
}
super.paint(g);
}
示例6: getListCellRendererComponent
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
public Component getListCellRendererComponent(
JList<?> list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
{
setComponentOrientation(list.getComponentOrientation());
Color bg = null;
Color fg = null;
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {
bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");
isSelected = true;
}
if (isSelected) {
setBackground(bg == null ? list.getSelectionBackground() : bg);
setForeground(fg == null ? list.getSelectionForeground() : fg);
}
else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
if (value instanceof Icon) {
setIcon((Icon)value);
setText("");
}
else {
setIcon(null);
setText((value == null) ? "" : value.toString());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
Border border = null;
if (cellHasFocus) {
if (isSelected) {
border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
}
if (border == null) {
border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
}
} else {
border = getNoFocusBorder();
}
setBorder(border);
return this;
}
示例7: updateBackground
import sun.swing.DefaultLookup; //导入方法依赖的package包/类
/**
* Updates the background of the text component based on whether the
* text component is editable and/or enabled.
*
* @param c the JTextComponent that needs its background color updated
*/
private void updateBackground(JTextComponent c) {
// This is a temporary workaround.
// This code does not correctly deal with Synth (Synth doesn't use
// properties like this), nor does it deal with the situation where
// the developer grabs the color from a JLabel and sets it as
// the background for a JTextArea in all look and feels. The problem
// scenario results if the Color obtained for the Label and TextArea
// is ==, which is the case for the windows look and feel.
// Until an appropriate solution is found, the code is being
// reverted to what it was before the original fix.
if (this instanceof SynthUI || (c instanceof JTextArea)) {
return;
}
Color background = c.getBackground();
if (background instanceof UIResource) {
String prefix = getPropertyPrefix();
Color disabledBG =
DefaultLookup.getColor(c, this, prefix + ".disabledBackground", null);
Color inactiveBG =
DefaultLookup.getColor(c, this, prefix + ".inactiveBackground", null);
Color bg =
DefaultLookup.getColor(c, this, prefix + ".background", null);
/* In an ideal situation, the following check would not be necessary
* and we would replace the color any time the previous color was a
* UIResouce. However, it turns out that there is existing code that
* uses the following inadvisable pattern to turn a text area into
* what appears to be a multi-line label:
*
* JLabel label = new JLabel();
* JTextArea area = new JTextArea();
* area.setBackground(label.getBackground());
* area.setEditable(false);
*
* JLabel's default background is a UIResource. As such, just
* checking for UIResource would have us always changing the
* background away from what the developer wanted.
*
* Therefore, for JTextArea/JEditorPane, we'll additionally check
* that the color we're about to replace matches one that was
* installed by us from the UIDefaults.
*/
if ((c instanceof JTextArea || c instanceof JEditorPane)
&& background != disabledBG
&& background != inactiveBG
&& background != bg) {
return;
}
Color newColor = null;
if (!c.isEnabled()) {
newColor = disabledBG;
}
if (newColor == null && !c.isEditable()) {
newColor = inactiveBG;
}
if (newColor == null) {
newColor = bg;
}
if (newColor != null && newColor != background) {
c.setBackground(newColor);
}
}
}